foxtrot9
foxtrot9

Reputation: 364

VSCode doesn't delete older version of extension

I am developer behind a more clean Monokai Theme on VScode. [It is more of a simple hack.]

https://marketplace.visualstudio.com/items?itemName=Mit.Monokai-Polished

Whenever I release a minor update VScode doesn't delete older version from /extensions folder after reloading the window. How do I remove this bug.

My source code is for extension is available at this repo.

Upvotes: 14

Views: 7702

Answers (2)

shadowz1337
shadowz1337

Reputation: 889

Restarting VS Code fixes the issue sometimes, but not all the time.

Ended up writing a script to clean up old extensions consistently.

function global:VSCode_Delete_Extensions
{
    param (
        [Parameter(Mandatory=$true)]
        [string]$FolderPath
    )

    # Get all subfolders in the specified directory
    $subfolders = Get-ChildItem -Path $FolderPath -Directory

    # Create a hashtable to store folder names and their respective paths
    $folderNameHash = @{}

    foreach ($folder in $subfolders) {

        $Shrink_Folder_Name_Length = [math]::Ceiling($folder.Name.Length * 0.10)
        $Shrink_Folder_Name_Length = $folder.Name.Length - $Shrink_Folder_Name_Length
        $key = $folder.Name.Substring(0, [Math]::Min($Shrink_Folder_Name_Length, $folder.Name.Length))

        if (-not $folderNameHash.ContainsKey($key)) {
            $folderNameHash[$key] = @($folder)
        }
        else {
            $folderNameHash[$key] += $folder
        }
    }

    # List to hold folders to be deleted
    $foldersToDelete = @()

    # Identify the folder with the oldest creation date for each key
    foreach ($key in $folderNameHash.Keys) {
        if ($folderNameHash[$key].Count -gt 1) {
            Write-output ""
            Write-Output "Similar folders for key '$key':"

            # Identify the folder with the oldest creation date
            $oldestFolder = $folderNameHash[$key] | Sort-Object CreationTime | Select-Object -First 1
            $foldersToDelete += $oldestFolder

            foreach ($folder in $folderNameHash[$key]) {
                $modifiedDate = $folder.LastWriteTime
                $createdDate = $folder.CreationTime
                Write-Output ("`t" + $folder.FullName + " (Modified: $modifiedDate, Created: $createdDate)")
            }
        }
    }
    
    write-host ""
    write-host ""
    write-host ""

    # Delete the folders in $foldersToDelete
    foreach ($folder in $foldersToDelete) {
        Write-Output "Deleting folder: $($folder.FullName)"
        #Remove-Item -Path $folder.FullName -Recurse -Force
        Remove-Item -Path $folder.FullName -Recurse -whatif
    }
}

Just call the function VSCode_Delete_Extensions and provide a folder path. Use the whatif to check what's gonna be deleted and then uncomment the line above to actually delete the extensions.

Upvotes: 2

alefragnani
alefragnani

Reputation: 3243

The older version will not be deleted if you just reload VSCode (clicking the Reload button in Extensions tab or using the Reload Window command. In order to really delete the older version, you need to Restart VSCode (close and reopen, all instances).

By the way, it appears to be designed this way, and not a bug. (related issue in VSCode repo).

Upvotes: 18

Related Questions