-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[AssetMapper] Fix in-file imports to resolve via filesystem #52349
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
[AssetMapper] Fix in-file imports to resolve via filesystem #52349
Conversation
@@ -38,23 +37,29 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac | |||
{ | |||
return preg_replace_callback(self::ASSET_URL_PATTERN, function ($matches) use ($asset, $assetMapper) { | |||
try { | |||
$resolvedPath = $this->resolvePath(\dirname($asset->logicalPath), $matches[1]); | |||
$resolvedSourcePath = Path::join(\dirname($asset->sourcePath), $matches[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit unrelated: let's let Path
do the work
// avoid warning about vendor imports - these are often comments | ||
if ($asset->isVendor) { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just represents a reorg so we can return earlier
@@ -38,23 +37,29 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac | |||
{ | |||
return preg_replace_callback(self::ASSET_URL_PATTERN, function ($matches) use ($asset, $assetMapper) { | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we can ignore this. In practice, our preg_replace_callback()
will return a string. But if there is some change we want to make to satisfy psalm, we can.
Thank you @weaverryan. |
f7f3574
to
659c635
Compare
This PR was merged into the 6.4 branch. Discussion ---------- [AssetMapper] Fixing merge | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | None | License | MIT Fixing the merge of #52323, #52331 and #52349 Also tested on a real project locally to verify the moving pieces :). Thanks! Commits ------- 99d5cbb [AssetMapper] Fixing merge from multiple PR's
…e importmap entry path (weaverryan) This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [AssetMapper] Fixing bug where JSCompiler used non-absolute importmap entry path | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | None | License | MIT Introduced over the weekend in #52349. The `path` key inside `importmap.php` can be a full filesystem path or it can start with `./` to indicate a relative path to the root directory. That has been the case for weeks. In #52349, when start using the `path` of an importmap entry to find the `MappedAsset`. When doing that, I didn't consider the case where `path` is a relative path. This PR fixes that and moves the code handling this into `ImportMapConfigReader` so that we're not repeating it in several places. Cheers! Commits ------- 31d04ef [AssetMapper] Fixing bug where JSCompiler used non-absolute importmap entry path
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Adding support for AssetMapper 6.4 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | None | License | MIT Change for AssetMapper 6.4 support. This is 2 main things: A) Changes needed after symfony/symfony#52349 with removal of trait + absolute import paths B) Outputting `autoimport` via `{{ importmap() }}` function / deprecate `ux_controller_link_tags()`. TODO: * I still need to the React/Svelte/Vue support to double-check it's all good for both 6.3 and 6.4. * Finish lazy autoimport * Make sure `controllers.json` is properly a config cache file resource for appropriate files Cheers! Commits ------- 05bcb98 Adding support for AssetMapper 6.4
Hi!
Another fix from further testing in the complex world!
tl;dr
Relative imports in CSS & JS files are now resolved via the filesystem path, not the AssetMapper "logical path".Full Explanation
In AssetMapper, we configure different paths/directories, which exposes them to the public directory. If you need to fetch the info about an asset, you can use its "logical path".
However, when you're inside of a JavaScript or CSS file, these "asset mapper" paths or "logical asset paths" are correctly irrelevant. Instead, you should code as if all of your files are already public and won't be moved around:
This PR fixes case 2️⃣ which previously did not work. Before, we used
../vendor/foo/bar/assets/baz.js
and the "asset mapper logical path" of the importing file (app.js
) and tried to construct a final, logical path from that. But because of the../vendor
, that went above theapp.js
root, and we panicked. Even if we didn't panic, logical paths should not be relevant here. Instead, it's simpler: the relative import inapp.js
uses the filesystem path. Of course, if the final file -/vendor/foo/bar/assets/baz.js
is not, itself, in some AssetMapper path, an clear exception is thrown (if the file is not exposed publicly, we can't resolve a proper path to it).Cheers!