From 66d94cf387f98ca5472c9d1a7d2d4d9dcf0f9f22 Mon Sep 17 00:00:00 2001 From: oznu Date: Thu, 25 Nov 2021 20:51:32 +1100 Subject: [PATCH] fix hb-servce update-node updater --- CHANGELOG.md | 5 +++++ src/bin/hb-service.ts | 18 ++++++++++++++++++ src/bin/platforms/darwin.ts | 3 +++ src/bin/platforms/linux.ts | 3 +++ 4 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1de796818..7bb74a98e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,15 @@ All notable changes to this project will be documented in this file. This projec ## NEXT +### Bug Fixes + +* **System:** Added a fix to the [`hb-service update-node`](https://github.com/oznu/homebridge-config-ui-x/wiki/Homebridge-Service-Command#update-nodejs) command to prevent it breaking npm when uprading from Node 14 to 16 + ### Other Changes * **i18n:** Improvements to Ukrainian language translations ([#1197](https://github.com/oznu/homebridge-config-ui-x/pull/1197)) * **i18n:** Improvements to Thai language translations ([#1200](https://github.com/oznu/homebridge-config-ui-x/pull/1200)) +* **i18n:** Improvements to Traditional Chinese language translations ([#1240](https://github.com/oznu/homebridge-config-ui-x/pull/1240)) * **Plugins:** The following features have been added to assist plugin developers building [custom plugin user interfaces](https://github.com/homebridge/plugin-ui-utils): * The "loading" spinner is now correctly shown on top of schema generated forms ([#1198](https://github.com/oznu/homebridge-config-ui-x/pull/1198)) diff --git a/src/bin/hb-service.ts b/src/bin/hb-service.ts index 50b35ceb8..3d21b8a75 100644 --- a/src/bin/hb-service.ts +++ b/src/bin/hb-service.ts @@ -1098,6 +1098,24 @@ export class HomebridgeServiceHelper { } } + /** + * Remove npm package + */ + public async removeNpmPackage(npmInstallPath: string) { + if (!await fs.pathExists(npmInstallPath)) { + return; + } + + const spinner = ora(`Cleaning up npm at ${npmInstallPath}...`).start(); + + try { + await fs.remove(npmInstallPath); + spinner.succeed(`Cleaned up npm at at ${npmInstallPath}`); + } catch (e) { + spinner.fail(e.message); + } + } + /** * Check the current status of the Homebridge UI by calling it's API */ diff --git a/src/bin/platforms/darwin.ts b/src/bin/platforms/darwin.ts index 667b3cae1..c263c179e 100644 --- a/src/bin/platforms/darwin.ts +++ b/src/bin/platforms/darwin.ts @@ -240,6 +240,9 @@ export class DarwinInstaller { unlink: true, }; + // remove npm package as this can cause issues when overwritten by the node tarball + await this.hbService.removeNpmPackage(path.resolve(targetPath, 'lib', 'node_modules', 'npm')); + // extract await this.hbService.extractNodejs(job.target, extractConfig); diff --git a/src/bin/platforms/linux.ts b/src/bin/platforms/linux.ts index be94f2e7d..54cdb4079 100644 --- a/src/bin/platforms/linux.ts +++ b/src/bin/platforms/linux.ts @@ -287,6 +287,9 @@ export class LinuxInstaller { unlink: true, }; + // remove npm package as this can cause issues when overwritten by the node tarball + await this.hbService.removeNpmPackage(path.resolve(targetPath, 'lib', 'node_modules', 'npm')); + // extract await this.hbService.extractNodejs(job.target, extractConfig);