8000 [AssetMapper] Fixing js sourceMappingURL extraction when sourceMappingURL used in code by weaverryan · Pull Request #52567 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[AssetMapper] Fixing js sourceMappingURL extraction when sourceMappingURL used in code #52567

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ private function makeImportsBare(string $content, array &$dependencies): string
}, $content);

// source maps are not also downloaded - so remove the sourceMappingURL
$content = preg_replace('{//# sourceMappingURL=.*$}m', '', $content);
// remove the final one only (in case sourceMappingURL is used in the code)
if (false !== $lastPos = strrpos($content, '//# sourceMappingURL=')) {
$content = substr($content, 0, $lastPos).preg_replace('{//# sourceMappingURL=.*$}m', '', substr($content, $lastPos));
}

return preg_replace('{/\*# sourceMappingURL=[^ ]*+ \*/}', '', $content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,30 @@ public static function provideDownloadPackagesTests()
],
];

yield 'css file removes importmap' => [
yield 'js sourcemap is correctly removed when sourceMapping appears in the JS' => [
[
'es-module-shims' => self::createRemoteEntry('es-module-shims', version: '1.8.2'),
],
[
[
'url' => '/es-module-shims@1.8.2/+esm',
'body' => <<<'EOF'
const je="\n//# sourceURL=",Ue="\n//# sourceMappingURL=",Me=/^(text|application)\/(x-)?javascript(;|$)/,_e=/^(application)\/wasm(;|$)/,Ie=/^(text|application)\/json(;|$)/,Re=/^(text|application)\/css(;|$)/,Te=/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;export{t as default};
//# sourceMappingURL=/sm/ef3916de598f421a779ba0e69af94655b2043095cde2410cc01893452d893338.map
EOF
],
],
[
'es-module-shims' => [
'content' => <<<'EOF'
const je="\n//# sourceURL=",Ue="\n//# sourceMappingURL=",Me=/^(text|application)\/(x-)?javascript(;|$)/,_e=/^(application)\/wasm(;|$)/,Ie=/^(text|application)\/json(;|$)/,Re=/^(text|application)\/css(;|$)/,Te=/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;export{t as default};
EOF,
'dependencies' => [],
],
],
];

yield 'css file removes sourcemap' => [
['lodash' => self::createRemoteEntry('bootstrap/dist/bootstrap.css', version: '5.0.6', type: ImportMapType::CSS)],
[
[
Expand Down
0