11// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
22
3- import { EXTENSION_NS } from "./constants " ;
3+ import { type ApprovedConfigPaths , getDenoPathInfo } from "./config_paths " ;
44
55import * as fs from "fs" ;
66import * as os from "os" ;
@@ -28,13 +28,22 @@ export function assert(cond: unknown, msg = "Assertion failed."): asserts cond {
2828
2929/** Returns the absolute path to an existing deno command or
3030 * the "deno" command name if not found. */
31- export async function getDenoCommandName ( ) {
32- return await getDenoCommandPath ( ) ?? "deno" ;
31+ export async function getDenoCommandName ( approvedPaths : ApprovedConfigPaths ) {
32+ return await getDenoCommandPath ( approvedPaths ) ?? "deno" ;
3333}
3434
35- /** Returns the absolute path to an existing deno command. */
36- export async function getDenoCommandPath ( ) {
37- const command = getWorkspaceConfigDenoExePath ( ) ;
35+ /** Returns the absolute path to an existing deno command.
36+ * Returns undefined if the path is not approved by the user. */
37+ export async function getDenoCommandPath ( approvedPaths : ApprovedConfigPaths ) {
38+ const pathInfo = getDenoPathInfo ( ) ;
39+
40+ // check for approval if using a workspace-configured path
41+ const approved = await approvedPaths . promptForApproval ( pathInfo ) ;
42+ if ( ! approved ) {
43+ return await getDefaultDenoCommand ( ) ;
44+ }
45+
46+ const command = pathInfo ?. path ;
3847 const workspaceFolders = workspace . workspaceFolders ;
3948 if ( ! command || ! workspaceFolders ) {
4049 return command ?? await getDefaultDenoCommand ( ) ;
@@ -52,17 +61,6 @@ export async function getDenoCommandPath() {
5261 }
5362}
5463
55- function getWorkspaceConfigDenoExePath ( ) {
56- const exePath = workspace . getConfiguration ( EXTENSION_NS )
57- . get < string > ( "path" ) ;
58- // it is possible for the path to be blank. In that case, return undefined
59- if ( typeof exePath === "string" && exePath . trim ( ) . length === 0 ) {
60- return undefined ;
61- } else {
62- return exePath ;
63- }
64- }
65-
6664async function getDefaultDenoCommand ( ) {
6765 // Adapted from https://github.com/npm/node-which/blob/master/which.js
6866 // Within vscode it will do `require("child_process").spawn("deno")`,
@@ -117,9 +115,10 @@ async function getDefaultDenoCommand() {
117115
118116export async function getDenoInfoJson (
119117 outputChannel : vscode . OutputChannel ,
118+ approvedPaths : ApprovedConfigPaths ,
120119) : Promise < DenoInfoJson | null > {
121120 try {
122- const command = await getDenoCommandName ( ) ;
121+ const command = await getDenoCommandName ( approvedPaths ) ;
123122 const { stdout, stderr, status, error } = spawnSync ( command , [
124123 "info" ,
125124 "--json" ,
0 commit comments