Skip to content

[AssetMapper] Fix import map package parsing with an @ namespace #50206

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

Conversation

weaverryan
Copy link
Member

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets None
License MIT
Doc PR Not needed

This method is used with the importmap:require command - e.g.

./bin/console importmap:require @hotwired/stimulus

It parses the string into the package name and potential version (and something called a "registry" which is specific to jspm). The original regex didn't account for namespaced packages.

Cheers!

@nicolas-grekas
Copy link
Member

Thank you @weaverryan.

@nicolas-grekas nicolas-grekas merged commit 2757c2f into symfony:6.3 May 2, 2023
@@ -111,8 +111,8 @@ public function update(): array
*/
public static function parsePackageName(string $packageName): ?array
{
// https://regex101.com/r/58bl9L/1
$regex = '/(?:(?P<registry>[^:\n]+):)?(?P<package>[^@\n]+)(?:@(?P<version>[^\s\n]+))?/';
// https://regex101.com/r/d99BEc/1
Copy link
Member

Choose a reason for hiding this comment

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

I would remove this comment entirely. Someone wanting to get the regex explanation on regex101.com can copy-paste the regex instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I got this idea from @dunglas - the nice thing about it is that the regex includes a bunch of examples. So if there is a problem in the future, you can quickly open this to see what the passing test cases are and then either validate that (A) the situation you are having trouble with SHOULD be working or (B) that your test case was never included.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, the main benefit it that we can add tests for the regex.

@weaverryan weaverryan deleted the import-map-fix-package-parsing branch May 2, 2023 13:01
@fabpot fabpot mentioned this pull request May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants