@@ -417,6 +417,48 @@ public static function providePathsCanUpdateTests(): iterable
417417 ];
418418 }
419419
420+ public function testCompileHandlesCircularRelativeAssets ()
421+ {
422+ $ appAsset = new MappedAsset ('app.js ' , 'anythingapp ' , '/assets/app.js ' );
423+ $ otherAsset = new MappedAsset ('other.js ' , 'anythingother ' , '/assets/other.js ' );
424+
425+ $ importMapConfigReader = $ this ->createMock (ImportMapConfigReader::class);
426+ $ assetMapper = $ this ->createMock (AssetMapperInterface::class);
427+ $ assetMapper ->expects ($ this ->once ())
428+ ->method ('getAsset ' )
429+ ->with ('other.js ' )
430+ ->willThrowException (new CircularAssetsException ($ otherAsset ));
431+
432+ $ compiler = new JavaScriptImportPathCompiler ($ importMapConfigReader );
433+ $ input = 'import "./other.js"; ' ;
434+ $ compiler ->compile ($ input , $ appAsset , $ assetMapper );
435+ $ this ->assertCount (1 , $ appAsset ->getJavaScriptImports ());
436+ $ this ->assertSame ($ otherAsset , $ appAsset ->getJavaScriptImports ()[0 ]->asset );
437+ }
438+
439+ public function testCompileHandlesCircularBareImportAssets ()
440+ {
441+ $ bootstrapAsset = new MappedAsset ('bootstrap ' , 'anythingbootstrap ' , '/assets/bootstrap.js ' );
442+ $ popperAsset = new MappedAsset ('@popperjs/core ' , 'anythingpopper ' , '/assets/popper.js ' );
443+
444+ $ importMapConfigReader = $ this ->createMock (ImportMapConfigReader::class);
445+ $ importMapConfigReader ->expects ($ this ->once ())
446+ ->method ('findRootImportMapEntry ' )
447+ ->with ('@popperjs/core ' )
448+ ->willReturn (ImportMapEntry::createRemote ('@popperjs/core ' , ImportMapType::JS , '/path/to/vendor/@popperjs/core.js ' , '1.2.3 ' , 'could_be_anything ' , false ));
449+ $ assetMapper = $ this ->createMock (AssetMapperInterface::class);
450+ $ assetMapper ->expects ($ this ->once ())
451+ ->method ('getAssetFromSourcePath ' )
452+ ->with ('/path/to/vendor/@popperjs/core.js ' )
453+ ->willThrowException (new CircularAssetsException ($ popperAsset ));
454+
455+ $ compiler = new JavaScriptImportPathCompiler ($ importMapConfigReader );
456+ $ input = 'import "@popperjs/core"; ' ;
457+ $ compiler ->compile ($ input , $ bootstrapAsset , $ assetMapper );
458+ $ this ->assertCount (1 , $ bootstrapAsset ->getJavaScriptImports ());
459+ $ this ->assertSame ($ popperAsset , $ bootstrapAsset ->getJavaScriptImports ()[0 ]->asset );
460+ }
461+
420462 /**
421463 * @dataProvider provideMissingImportModeTests
422464 */
@@ -487,7 +529,7 @@ public function testErrorMessageAvoidsCircularException()
487529 }
488530
489531 if ('htmx.js ' === $ logicalPath ) {
490- throw new CircularAssetsException ();
532+ throw new CircularAssetsException (new MappedAsset ( ' htmx.js ' ) );
491533 }
492534 });
493535
0 commit comments