-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { EXTENSION_NS } from "./constants"; | ||
import * as tasks from "./tasks"; | ||
import { UpgradeAvailable } from "./types"; | ||
import { assert, getDenoCommandName } from "./util"; | ||
import * as vscode from "vscode"; | ||
|
||
export async function denoUpgradePromptAndExecute( | ||
{ latestVersion, isCanary }: UpgradeAvailable, | ||
) { | ||
const config = vscode.workspace.getConfiguration(EXTENSION_NS); | ||
let prompt = isCanary | ||
? `A new canary release of Deno is available: ${latestVersion.slice(0, 7)}.` | ||
: `A new release of Deno is available: ${latestVersion}.`; | ||
prompt += " Would you like to upgrade?"; | ||
const selection = await vscode.window.showInformationMessage( | ||
prompt, | ||
"Upgrade", | ||
"Dismiss", | ||
); | ||
if (selection !== "Upgrade") { | ||
return; | ||
} | ||
const args = ["upgrade"]; | ||
if (config.get("unstable")) { | ||
args.push("--unstable"); | ||
} | ||
if (isCanary) { | ||
args.push("--canary"); | ||
} | ||
args.push("--version"); | ||
args.push(latestVersion); | ||
const env = {} as Record<string, string>; | ||
const cacheDir: string | undefined | null = config.get("cache"); | ||
if (cacheDir?.trim()) { | ||
env["DENO_DIR"] = cacheDir.trim(); | ||
} | ||
const definition: tasks.DenoTaskDefinition = { | ||
type: tasks.TASK_TYPE, | ||
command: "upgrade", | ||
args, | ||
env, | ||
}; | ||
assert(vscode.workspace.workspaceFolders); | ||
const target = vscode.workspace.workspaceFolders[0]; | ||
const denoCommand = await getDenoCommandName(); | ||
const task = tasks.buildDenoTask( | ||
target, | ||
denoCommand, | ||
definition, | ||
"upgrade", | ||
args, | ||
["$deno"], | ||
); | ||
task.presentationOptions = { | ||
reveal: vscode.TaskRevealKind.Always, | ||
panel: vscode.TaskPanelKind.Dedicated, | ||
clear: true, | ||
}; | ||
const execution = await vscode.tasks.executeTask(task); | ||
const disposable = vscode.tasks.onDidEndTask((event) => { | ||
if (event.execution == execution) { | ||
disposable.dispose(); | ||
vscode.commands.executeCommand("deno.client.restart"); | ||
} | ||
}); | ||
} |