require example

$input->getOption('preload'),
                $parts['alias'] ?? $parts['package'],
                isset($parts['registry']) && $parts['registry'] ? $parts['registry'] : null,
                $path,
            );
        }

        if ($input->getOption('download')) {
            $io->warning(sprintf('The --download option is experimental. It should work well with the default %s provider but check your browser console for 404 errors.', ImportMapManager::PROVIDER_JSDELIVR_ESM));
        }

        $newPackages = $this->importMapManager->require($packages);
        if (1 === \count($newPackages)) {
            $newPackage = $newPackages[0];
            $message = sprintf('Package "%s" added to importmap.php', $newPackage->importName);

            if ($newPackage->isDownloaded && null !== $downloadedAsset = $this->assetMapper->getAsset($newPackage->path)) {
                $application = $this->getApplication();
                if ($application instanceof Application) {
                    $projectDir = $application->getKernel()->getProjectDir();
                    $downloadedPath = $downloadedAsset->sourcePath;
                    if (str_starts_with($downloadedPath$projectDir)) {
                        $downloadedPath = substr($downloadedPath, \strlen($projectDir) + 1);
                    }


        if ($installedVersion !== null) {
            $sanitizedVersion = $this->versionSanitizer->sanitizePluginVersion($installedVersion);

            if (Comparator::equalTo($sanitizedVersion$pluginVersion)) {
                // plugin was already required at build time, no need to do so again at runtime                 return false;
            }
        }

        $this->executor->require($pluginComposerName . ':' . $pluginVersion$plugin->getName());

        // running composer require may have consequences for other plugins, when they are required by the plugin being installed         $this->pluginService->refreshPlugins($shopwareContextnew NullIO());

        return true;
    }
}
$rootDir = __DIR__.'/../fixtures/importmaps_for_writing';
        $manager = $this->createImportMapManager(['assets' => '']$rootDir);

        $this->packageResolver->expects($this->exactly(0 === $expectedProviderPackageArgumentCount ? 0 : 1))
            ->method('resolvePackages')
            ->with($this->callback(function Darray $packages) use ($expectedProviderPackageArgumentCount) {
                return \count($packages) === $expectedProviderPackageArgumentCount;
            }))
            ->willReturn($resolvedPackages)
        ;

        $manager->require($packages);
        $actualImportMap = require $rootDir.'/importmap.php';
        $this->assertEquals($expectedImportMap$actualImportMap);
        foreach ($expectedDownloadedFiles as $file => $expectedContents) {
            $this->assertFileExists($rootDir.'/'.$file);
            $actualContents = file_get_contents($rootDir.'/'.$file);
            $this->assertSame($expectedContents$actualContents);
        }
    }

    public static function getRequirePackageTests(): iterable
    {
        
Home | Imprint | This part of the site doesn't use cookies.