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

[AssetMapper] Bug fix for paths that start with the same string#50355

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

weaverryan
Copy link
Member

@weaverryanweaverryan commentedMay 17, 2023
edited
Loading

QA
Branch?6.3
Bug fix?yes
New feature?no
Deprecations?no
TicketsNone
LicenseMIT
Doc PRStill TODO

Hi!

This should be minor:

  1. Fixed a bug where if 1 asset path directory is a substring of another (e.g.assets/dir andassets/dir2), when you calledAssetMapperRepository::findLogicalPath() passing a filesystem path pointed atassets/dir2, it would incorrectly match something inassets/dir.

2) Allowedimportmap.php paths to be absolute. The use-case is for UX libraries. UX libraries WILL automatically add a "namespaced path" to the asset mapper. For example, the StimulusBundle I'm working on will likely expose asymfony/stimulus-bundle asset mapper namespace that points to theassets/ directory of that bundle. But, for users, I don't want this to be "another thing you need to know". So, the result of this PR is that, in the user'simportmap.php:

    '@symfony/stimulus-bundle' => [-        // "symfony/stimulus-bundle" is an asset path that points into that bundle-        'path' => 'symfony/stimulus-bundle/loader.js',+        'path' => __DIR__.'/../../assets/loader.js',    ],

The user points to the absolute file, WE figure out which "asset path" that's in, and everything works nicely.

UPDATE: I've removed this.

Cheers!

@@ -76,7 +76,7 @@ public function findLogicalPath(string $filesystemPath): ?string
}

foreach ($this->getDirectories() as $path => $namespace) {
if (!str_starts_with($filesystemPath, $path)) {
if (!str_starts_with($filesystemPath, $path.'/')) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think we're ok. These are all comparing filesystem paths - not the actual paths that are exposed to the user / importmap.

@weaverryanweaverryanforce-pushed theasset-mapper-import-map-absolute-paths branch from9f35611 to9158f05CompareMay 19, 2023 00:05
@weaverryanweaverryan changed the title[AssetMapper] Bug fix + allow import map absolute paths[AssetMapper] Bug fix for paths that start with the same stringMay 19, 2023
@carsonbotcarsonbot changed the title[AssetMapper] Bug fix for paths that start with the same stringBug fix for paths that start with the same stringMay 19, 2023
@weaverryan
Copy link
MemberAuthor

I've just simplified this - it's now just a simple bug fix. The "absolute path" thing might be cool. But in practice, during a UX bundle install, we'll useimportmap:require to update the importmap.php using#50363 and there was no graceful way, anyways, for that feature to output a string like__DIR__.'/...', which is what I wanted. So, let's just stick to using asset logical paths everywhere.

@carsonbotcarsonbot changed the titleBug fix for paths that start with the same string[AssetMapper] Bug fix for paths that start with the same stringMay 19, 2023
@nicolas-grekas
Copy link
Member

Thank you@weaverryan.

nicolas-grekas added a commit that referenced this pull requestMay 19, 2023
…yan)This PR was squashed before being merged into the 6.3 branch.Discussion----------Bug fix for paths that start with the same string| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       | None| License       | MIT| Doc PR        | Still TODOHi!This should be minor:1) Fixed a bug where if 1 asset path directory is a substring of another (e.g. `assets/dir` and `assets/dir2`), when you called `AssetMapperRepository::findLogicalPath()` passing a filesystem path pointed at `assets/dir2`, it would incorrectly match something in `assets/dir`.~~2) Allowed `importmap.php` paths to be absolute. The use-case is for UX libraries. UX libraries WILL automatically add a "namespaced path" to the asset mapper. For example, the StimulusBundle I'm working on will likely expose a `symfony/stimulus-bundle` asset mapper namespace that points to the `assets/` directory of that bundle. But, for users, I don't want this to be "another thing you need to know". So, the result of this PR is that, in the user's `importmap.php`:~~```diff    '`@symfony`/stimulus-bundle' => [-        // "symfony/stimulus-bundle" is an asset path that points into that bundle-        'path' => 'symfony/stimulus-bundle/loader.js',+        'path' => __DIR__.'/../../assets/loader.js',    ],```~~The user points to the absolute file, WE figure out which "asset path" that's in, and everything works nicely.~~UPDATE: I've removed this.Cheers!Commits-------51b9246 Bug fix for paths that start with the same string
@nicolas-grekasnicolas-grekasforce-pushed theasset-mapper-import-map-absolute-paths branch from97a03c2 to51b9246CompareMay 19, 2023 06:23
@weaverryanweaverryan deleted the asset-mapper-import-map-absolute-paths branchMay 19, 2023 10:15
@fabpotfabpot mentioned this pull requestMay 22, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stofstofstof left review comments

Assignees
No one assigned
Projects
None yet
Milestone
6.3
Development

Successfully merging this pull request may close these issues.

4 participants
@weaverryan@nicolas-grekas@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp