From d20f80acbe0badaf1d3734ce72eb900ebb6b4ab6 Mon Sep 17 00:00:00 2001 From: Renaud Heluin Date: Wed, 9 Oct 2024 20:04:56 +0200 Subject: [PATCH] fix: bad if on `os.plateform()` --- .../initHandlers/plugin_canInstall.ts | 70 +++++++++---------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/src/main/handlers/initHandlers/plugin_canInstall.ts b/src/main/handlers/initHandlers/plugin_canInstall.ts index 9dee037..07abe23 100644 --- a/src/main/handlers/initHandlers/plugin_canInstall.ts +++ b/src/main/handlers/initHandlers/plugin_canInstall.ts @@ -73,44 +73,38 @@ export const initSudoFixNpmDirRights = ( const mainLog = getMainLog().scope( 'main/initialization/initSudoFixNpmDirRights' ) - if (os.platform() === 'darwin' || os.platform() === 'linux') { - mainLog.debug(`Fix User rights on NPM Dir with sudo.`) - const toReturned = new ConfigData('fix_npm_user_rights') - return new Promise((resolve) => { - const libPath = path.join(`lib`, `node_modules`) - let cmd = `` - if (os.platform() === 'win32') { - cmd = `mkdir $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"` - } else { - cmd = `mkdir -p $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"` - } - sudoPrompt.exec( - cmd, - { name: 'Fix user permissions on Node' }, - (error, stdout, stderr) => { - if (error) { - mainLog.error(`exec error: ${error}`) - toReturned.error = error - toReturned.message = `CAN'T fix Npm user rights` - return resolve(toReturned) - } - if (stderr) mainLog.debug(`stderr: ${stderr}`) - if (stdout) { - const returned: string = (stdout as string).trim() - toReturned.result = true - toReturned.message = `User rights FIXED returned ${returned}` - // getMainWindow().webContents.send( - // channels.HOST_INFORMATIONS_BACK, - // toReturned - // ) - return resolve(toReturned) - } + mainLog.debug(`Fix User rights on NPM Dir with sudo.`) + const toReturned = new ConfigData('fix_npm_user_rights') + return new Promise((resolve) => { + const libPath = path.join(`lib`, `node_modules`) + let cmd = `` + if (os.platform() === 'win32') { + cmd = `mkdir $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"` + } else { + cmd = `mkdir -p $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"` + } + sudoPrompt.exec( + cmd, + { name: 'Fix user permissions on Node' }, + (error, stdout, stderr) => { + if (error) { + mainLog.error(`exec error: ${error}`) + toReturned.error = error + toReturned.message = `CAN'T fix Npm user rights` + return resolve(toReturned) } - ) - }) - } else { - mainLog.debug( - `NOT ON DARWIN/LINUX PLATFORM, CAN'T Fix User rights on NPM Dir.` + if (stderr) mainLog.debug(`stderr: ${stderr}`) + if (stdout) { + const returned: string = (stdout as string).trim() + toReturned.result = true + toReturned.message = `User rights FIXED returned ${returned}` + // getMainWindow().webContents.send( + // channels.HOST_INFORMATIONS_BACK, + // toReturned + // ) + return resolve(toReturned) + } + } ) - } + }) }