Skip to content

Commit

Permalink
[AssetMapper] Fix JsDeliver import regexp
Browse files Browse the repository at this point in the history
Following import were not handled, due to the `$`.

```js
import jQuery$1 from "/npm/[email protected]/+esm";
```

This PR updates the regex to handle this case.
  • Loading branch information
smnandre committed Aug 20, 2024
1 parent adec1f6 commit 6a9672c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ImportMap/Resolver/JsDelivrEsmResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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 = '#(?:import\s*(?:\w+,)?(?:(?:\{[^}]*\}|\w+|\*\s*as\s+\w+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*)("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")#';
public const IMPORT_REGEX = '#(?:import\s*(?:[\w$]+,)?(?:(?:\{[^}]*\}|[\w$]+|\*\s*as\s+[\w$]+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*)("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")#';

private const ES_MODULE_SHIMS = 'es-module-shims';

Expand Down
7 changes: 7 additions & 0 deletions Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,13 @@ public static function provideImportRegex(): iterable
['datatables.net-select', '1.7.0'],
],
];

yield 'import with name containing a dollar sign' => [
'import jQuery$1 from "/npm/[email protected]/+esm";',
[
['jquery', '3.7.0'],
],
];
}

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

0 comments on commit 6a9672c

Please sign in to comment.