Skip to content

Commit

Permalink
minor #52351 [AssetMapper] Fixing merge (weaverryan)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xabbuh committed Oct 29, 2023
2 parents d15c34b + 99d5cbb commit b1ec74b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Expand Up @@ -172,7 +172,12 @@ private function findAssetForRelativeImport(string $importedModule, MappedAsset
return null;
}

$dependentAsset = $assetMapper->getAsset($resolvedSourcePath);
try {
$dependentAsset = $assetMapper->getAssetFromSourcePath($resolvedSourcePath);
} catch (CircularAssetsException $exception) {
$dependentAsset = $exception->getIncompleteMappedAsset();
}

if ($dependentAsset) {
return $dependentAsset;
}
Expand Down
Expand Up @@ -173,7 +173,6 @@ public static function provideCompileTests(): iterable
];

yield 'importing_non_existent_file_without_strict_mode_is_ignored_and_no_import_added' => [
'sourceLogicalName' => 'app.js',
'input' => "import './non-existent.js';",
'expectedJavaScriptImports' => [],
];
Expand Down Expand Up @@ -277,7 +276,6 @@ public static function provideCompileTests(): iterable
];

yield 'absolute_import_ignored_and_no_dependency_added' => [
'sourceLogicalName' => 'app.js',
'input' => 'import "https://example.com/module.js";',
'expectedJavaScriptImports' => [],
];
Expand Down Expand Up @@ -415,14 +413,14 @@ public static function providePathsCanUpdateTests(): iterable

public function testCompileHandlesCircularRelativeAssets()
{
$appAsset = new MappedAsset('app.js', 'anythingapp', '/assets/app.js');
$otherAsset = new MappedAsset('other.js', 'anythingother', '/assets/other.js');
$appAsset = new MappedAsset('app.js', '/project/assets/app.js', '/assets/app.js');
$otherAsset = new MappedAsset('other.js', '/project/assets/other.js', '/assets/other.js');

$importMapConfigReader = $this->createMock(ImportMapConfigReader::class);
$assetMapper = $this->createMock(AssetMapperInterface::class);
$assetMapper->expects($this->once())
->method('getAsset')
->with('other.js')
->method('getAssetFromSourcePath')
->with('/project/assets/other.js')
->willThrowException(new CircularAssetsException($otherAsset));

$compiler = new JavaScriptImportPathCompiler($importMapConfigReader);
Expand Down

0 comments on commit b1ec74b

Please sign in to comment.