From 5f64127f5bc47750993bbf57435074616f615278 Mon Sep 17 00:00:00 2001 From: CHaBou Date: Mon, 15 Jan 2018 23:22:41 +0100 Subject: [PATCH] Fix CLI installation on Windows (#2600) * Protect against missing PATH user env var * Protect against different cases for PATH user env var name Fixes #2580 --- app/utils/cli-install.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/utils/cli-install.js b/app/utils/cli-install.js index 342099c6..438b5588 100644 --- a/app/utils/cli-install.js +++ b/app/utils/cli-install.js @@ -60,21 +60,26 @@ exports.addBinToUserPath = () => { // C:\Users\\AppData\Local\hyper const basePath = path.resolve(binPath, '../../..'); - const pathItem = items.find(item => item.name === 'Path'); - const pathParts = pathItem.value.split(';'); - const existingPath = pathParts.find(pathPart => pathPart === binPath); - if (existingPath) { - resolve(); - return; + const pathItem = items.find(item => item.name.toUpperCase() === 'PATH'); + + let newPathValue = binPath; + const pathItemName = pathItem ? pathItem.name : 'PATH'; + if (pathItem) { + const pathParts = pathItem.value.split(';'); + const existingPath = pathParts.find(pathPart => pathPart === binPath); + if (existingPath) { + resolve(); + return; + } + + // Because version is in path we need to remove old path if present and add current path + newPathValue = pathParts + .filter(pathPart => !pathPart.startsWith(basePath)) + .concat([binPath]) + .join(';'); } - // Because version is in path we need to remove old path if present and add current path - const newPathValue = pathParts - .filter(pathPart => !pathPart.startsWith(basePath)) - .concat([binPath]) - .join(';'); - - envKey.set(pathItem.name, Registry.REG_SZ, newPathValue, error => { + envKey.set(pathItemName, Registry.REG_SZ, newPathValue, error => { if (error) { reject(error); return;