protected function addSymlinks(PackageInterface $package, $targetRoot, array $pathMap, $mode = self::DUPLICATE_FAIL)
    {
        if (empty($pathMap)) {
            return;
        }

        $packageRoot = $this->getInstallPath($package);
        $actions     = [];

        // Check the file map first and make sure nothing exists.
        foreach ($pathMap as $sourcePath => $targetPath) {
            $source = $this->filesystem->normalizePath($packageRoot . ($sourcePath ? ('/'.$sourcePath) : ''));
            $target = $this->filesystem->normalizePath($targetRoot . '/' . $targetPath);

            if ($this->canAddSymlink($source, $target, $mode)) {
                $actions[$source] = $target;
            }
        }

        // Only actually create the links if the checks are successful to prevent orphans.
        foreach ($actions as $source => $target) {
            $this->logSymlink($source, $target);

            $this->filesystem->ensureDirectoryExists(dirname($target));

            if (Platform::isWindows()) {
                $success = @symlink($source, $target);
            } else {
                $success = $this->filesystem->relativeSymlink($source, $target);
            }

            if (!$success) {
                throw new \RuntimeException('Failed to create symlink ' . $target);
            }
        }
    }