From 6299268846d2869f4e2a767d3a40eb697b6be236 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Wed, 26 May 2021 20:55:44 +0800 Subject: [PATCH 1/2] fix: node version not update --- main/ipc/installNode.ts | 9 +++++++-- main/node/NvmManager.ts | 6 +++--- main/packageInfo/cli/cli.ts | 27 ++++++++++++++------------- package.json | 4 ++-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/main/ipc/installNode.ts b/main/ipc/installNode.ts index b664358..299dd20 100644 --- a/main/ipc/installNode.ts +++ b/main/ipc/installNode.ts @@ -36,8 +36,13 @@ export default () => { }); childProcess.on('message', ({ channel, data }: any) => { - if (channel === processChannel && (data.status === 'done')) { - killChannelChildProcess(childProcessMap, installChannel); + if (channel === processChannel) { + const { status, result } = data; + if (status === 'done') { + killChannelChildProcess(childProcessMap, installChannel); + } else if (status === 'success' && result && result.nodePath) { + process.env.PATH = `${result.nodePath.replace('/bin/node', '/bin')}${path.delimiter}${process.env.PATH}`; + } } sendMainWindow(channel, data); }); diff --git a/main/node/NvmManager.ts b/main/node/NvmManager.ts index 4bfba05..0310d21 100644 --- a/main/node/NvmManager.ts +++ b/main/node/NvmManager.ts @@ -58,10 +58,10 @@ class NvmManager implements INodeManager { }); cp.on('exit', () => { - this.nodePath = this.getCurrentNodePath(this.std); + const nodePath = this.getCurrentNodePath(this.std); const npmVersion = this.getCurrentNpmVersion(this.std); - - resolve({ nodeVersion: formattedVersion, npmVersion }); + this.nodePath = nodePath; + resolve({ nodeVersion: formattedVersion, npmVersion, nodePath }); }); }); }; diff --git a/main/packageInfo/cli/cli.ts b/main/packageInfo/cli/cli.ts index 4f5d223..8c37c73 100644 --- a/main/packageInfo/cli/cli.ts +++ b/main/packageInfo/cli/cli.ts @@ -4,35 +4,36 @@ import { DEFAULT_LOCAL_PACKAGE_INFO } from '../../constants'; import getVersionStatus from '../../utils/getVersionStatus'; import log from '../../utils/log'; -function getLocalToolInfo(name: string, latestVersion: string | null) { - const localToolInfo = { ...DEFAULT_LOCAL_PACKAGE_INFO }; +function getLocalCliInfo(name: string, latestVersion: string | null) { + const localCliInfo = { ...DEFAULT_LOCAL_PACKAGE_INFO }; // get the local path of cli try { - const toolPath = shell.which(name); - if (!toolPath) { - throw new Error(`Tool ${name} is not found.`); + const { stdout: cliPath } = shell.which(name); + + if (!cliPath) { + throw new Error(`Command ${name} is not found.`); } - localToolInfo.localPath = toolPath.stdout; + localCliInfo.localPath = cliPath; } catch (error) { log.error(error.message); - return localToolInfo; + return localCliInfo; } // get cli version try { const { stdout: cliVersion } = execa.sync( - localToolInfo.localPath, + localCliInfo.localPath, ['--version'], - { shell: true, extendEnv: false }, + { shell: true }, ); const cliVersionMatch = cliVersion.match(/(\d+(\.\d+)*)/); - localToolInfo.localVersion = cliVersionMatch ? cliVersionMatch[1] : cliVersion; + localCliInfo.localVersion = cliVersionMatch ? cliVersionMatch[1] : cliVersion; } catch (error) { log.error(`Tool ${name} version is not found. Error: ${error.message}`); } // get cli version status - localToolInfo.versionStatus = getVersionStatus(localToolInfo.localVersion, latestVersion); + localCliInfo.versionStatus = getVersionStatus(localCliInfo.localVersion, latestVersion); - return localToolInfo; + return localCliInfo; } -export default getLocalToolInfo; +export default getLocalCliInfo; diff --git a/package.json b/package.json index 1244fa4..643d34f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build": "rm -rf ./dist && npm run build:renderer && npm run build:main", "build:renderer": "cd ./renderer && npm run build", "build:main": "tsc --build ./main/tsconfig.json", - "package": "npm run build && npm run copy:static && NPM_CONFIG_ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-builder build --mac", + "package": "rm -rf release && npm run build && npm run copy:static && NPM_CONFIG_ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ electron-builder build --mac", "lint": "npm run eslint && npm run stylelint", "eslint": "eslint --ext .ts,.tsx,.js,.jsx ./", "eslint:fix": "npm run eslint -- --fix", @@ -97,4 +97,4 @@ "typescript": "^4.0.0", "wait-on": "^5.3.0" } -} +} \ No newline at end of file From ead5caec9839aeda4ef10275f3400f461bf0958a Mon Sep 17 00:00:00 2001 From: luhc228 Date: Thu, 27 May 2021 17:12:36 +0800 Subject: [PATCH 2/2] chore: comment --- main/ipc/installNode.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main/ipc/installNode.ts b/main/ipc/installNode.ts index 299dd20..2b2d64b 100644 --- a/main/ipc/installNode.ts +++ b/main/ipc/installNode.ts @@ -41,7 +41,10 @@ export default () => { if (status === 'done') { killChannelChildProcess(childProcessMap, installChannel); } else if (status === 'success' && result && result.nodePath) { - process.env.PATH = `${result.nodePath.replace('/bin/node', '/bin')}${path.delimiter}${process.env.PATH}`; + // nodeEnvPath e.g: /Users/xxx/.nvm/versions/node/v14.15.0/bin/path -> Users/xxx/.nvm/versions/node/v14.15.0/bin + const nodeEnvPath = result.nodePath.replace('/bin/node', '/bin'); + // process.env.PATH: /usr/local/bin -> /Users/xxx/.nvm/versions/node/v14.15.0/bin:/usr/local/bin + process.env.PATH = `${nodeEnvPath}${path.delimiter}${process.env.PATH}`; } } sendMainWindow(channel, data);