From 48981a13090b53a411d3937dca6557af1d128872 Mon Sep 17 00:00:00 2001 From: ablause <46499306+ablause@users.noreply.github.com> Date: Sun, 18 Apr 2021 23:42:10 +0200 Subject: [PATCH] feat: add env variables support on deno.path --- client/src/extension.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client/src/extension.ts b/client/src/extension.ts index bada7064..c419105f 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -227,6 +227,8 @@ async function getCommand() { const defaultCommand = await getDefaultDenoCommand(); if (!command || !workspaceFolders) { command = command ?? defaultCommand; + } else if ((/[%|$]/g).test(command)) { + command = resolveEnvPath(command); } else if (!path.isAbsolute(command)) { // if sent a relative path, iterate over workspace folders to try and resolve. const list = []; @@ -244,6 +246,26 @@ async function getCommand() { command = list.shift() ?? defaultCommand; } return command; + + function resolveEnvPath(value: string) { + let pathToResolve: string; + switch (os.platform()) { + case 'darwin': + case 'linux': + pathToResolve = value.replace(/\$([\w]+)/g, (_, key) => { + if (key === 'HOME') return os.homedir(); + return process.env[key] ?? ''; + }) + break; + case 'win32': + pathToResolve = value.replace(/%([\w]+)%/g, (_, key) => process.env[key] ?? ''); + break; + default: + pathToResolve = value; + } + + return path.normalize(pathToResolve); + } } function getDefaultDenoCommand() {