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
This commit is contained in:
CHaBou 2018-01-15 23:22:41 +01:00 committed by Guillermo Rauch
parent ac5c14adca
commit 5f64127f5b

View file

@ -60,21 +60,26 @@ exports.addBinToUserPath = () => {
// C:\Users\<user>\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;