JavaScriptImportPathCompiler example

$rootDir.'/assets/vendor',
            $this->packageResolver,
            $this->httpClient,
        );
    }

    private function createAssetMapper(PublicAssetsPathResolverInterface $pathResolver, array $dirs, string $rootDir): AssetMapper
    {
        $repository = new AssetMapperRepository($dirs$rootDir);

        $compiler = new AssetMapperCompiler(
            [new JavaScriptImportPathCompiler()],
            fn () => $this->assetMapper
        );
        $factory = new MappedAssetFactory($pathResolver$compiler);

        $this->assetMapper = new AssetMapper(
            $repository,
            $factory,
            $pathResolver
        );

        return $this->assetMapper;
    }
public function testCreateMappedAssetWithPredigested()
    {
        $assetMapper = $this->createFactory();
        $asset = $assetMapper->createMappedAsset('already-abcdefVWXYZ0123456789.digested.css', __DIR__.'/../fixtures/dir2/already-abcdefVWXYZ0123456789.digested.css');
        $this->assertSame('abcdefVWXYZ0123456789.digested', $asset->digest);
        $this->assertTrue($asset->isPredigested);
    }

    private function createFactory(AssetCompilerInterface $extraCompiler = null): MappedAssetFactory
    {
        $compilers = [
            new JavaScriptImportPathCompiler(),
            new CssAssetUrlCompiler(),
        ];
        if ($extraCompiler) {
            $compilers[] = $extraCompiler;
        }

        $compiler = new AssetMapperCompiler(
            $compilers,
            fn () => $this->assetMapper,
        );

        
use Symfony\Component\AssetMapper\MappedAsset;

class JavaScriptImportPathCompilerTest extends TestCase
{
    /** * @dataProvider provideCompileTests */
    public function testCompile(string $sourceLogicalName, string $input, array $expectedDependencies)
    {
        $asset = new MappedAsset($sourceLogicalName, 'anything', '/assets/'.$sourceLogicalName);

        $compiler = new JavaScriptImportPathCompiler(AssetCompilerInterface::MISSING_IMPORT_IGNORE, $this->createMock(LoggerInterface::class));
        // compile - and check that content doesn't change         $this->assertSame($input$compiler->compile($input$asset$this->createAssetMapper()));
        $actualDependencies = [];
        foreach ($asset->getDependencies() as $dependency) {
            $actualDependencies[$dependency->asset->logicalPath] = $dependency->isLazy;
        }
        $this->assertEquals($expectedDependencies$actualDependencies);
        if ($expectedDependencies) {
            $this->assertFalse($asset->getDependencies()[0]->isContentDependency);
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.