Skip to content

Instantly share code, notes, and snippets.

@jayu
Last active June 28, 2023 07:40
Show Gist options
  • Save jayu/6d8b32da0f13e0f53e89a9eb73ebaa94 to your computer and use it in GitHub Desktop.
Save jayu/6d8b32da0f13e0f53e89a9eb73ebaa94 to your computer and use it in GitHub Desktop.
Install vscode extension from vsix file hosted in the internet. It's useful for distributing private, maybe paid version of your free extension.
import { Uri } from 'vscode'
import * as vscode from 'vscode'
import fetch from 'node-fetch'
export function activate(context: vscode.ExtensionContext) {
const installPrivateVersionOfExtension = () => {
const fileBlob = await (
// Most likely you want to authenticate user to execute that request
await fetch('https://your.server.com/extension.vsix')
).blob()
const buffer = await fileBlob.arrayBuffer()
const storagePath = context.storageUri?.fsPath
const fileUri = Uri.file(`${storagePath}/extension.vsix`)
await vscode.workspace.fs.writeFile(fileUri, Buffer.from(buffer))
await vscode.commands.executeCommand(
'workbench.extensions.installExtension',
fileUri,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment