Skip to content

Commit

Permalink
retire use of pnpm and code references
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Oct 1, 2024
1 parent 69ac82d commit 16b7edf
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 136 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to `homebridge-config-ui-x` will be documented in this file.
### Other Changes

- update `@homebridge/hap-client` to `v2`
- retire use of `pnpm` and code references

### Homebridge Dependencies

Expand Down
10 changes: 2 additions & 8 deletions src/bin/hb-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ export class HomebridgeServiceHelper {
}

/**
* Install / Remove a plugin using pnpm (supported platforms only)
* Install / Remove a plugin (supported platforms only)
*/
private async npmPluginManagement(args: any[]) {
if (!this.enableHbServicePluginManagement) {
Expand Down Expand Up @@ -1361,13 +1361,7 @@ export class HomebridgeServiceHelper {
this.logger(`Path does not exist: "${cwd}"`, 'fail')
}

let cmd: string

if (process.env.UIX_USE_PNPM === '1') {
cmd = `pnpm -C "${cwd}" ${action} ${target.name}`
} else {
cmd = `npm --prefix "${cwd}" ${action} ${target.name}`
}
let cmd: string = `npm --prefix "${cwd}" ${action} ${target.name}`

if (action === 'add') {
cmd += `@${target.version}`
Expand Down
67 changes: 25 additions & 42 deletions src/bin/platforms/darwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,50 +112,33 @@ export class DarwinInstaller extends BasePlatform {

const targetNodeVersion = execSync('node -v').toString('utf8').trim()

if (this.isPackage() && process.env.UIX_USE_PNPM === '1' && process.env.UIX_CUSTOM_PLUGIN_PATH) {
// pnpm+package mode
const cwd = dirname(process.env.UIX_CUSTOM_PLUGIN_PATH)

if (!await pathExists(cwd)) {
this.hbService.logger(`Path does not exist: "${cwd}"`, 'fail')
process.exit(1)
}

execSync(`pnpm -C "${cwd}" rebuild`, {
cwd,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt plugins in ${process.env.UIX_CUSTOM_PLUGIN_PATH} for Node.js ${targetNodeVersion}.`, 'succeed')
} else {
// normal global npm setups
const npmGlobalPath = execSync('/bin/echo -n "$(npm -g prefix)/lib/node_modules"', {
env: Object.assign({
npm_config_loglevel: 'silent',
npm_update_notifier: 'false',
}, process.env),
}).toString('utf8')

execSync('npm rebuild --unsafe-perm', {
cwd: process.env.UIX_BASE_PATH,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt homebridge-config-ui-x for Node.js ${targetNodeVersion}.`, 'succeed')

if (all === true) {
// rebuild all modules
try {
execSync('npm rebuild --unsafe-perm', {
cwd: npmGlobalPath,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt plugins in ${npmGlobalPath} for Node.js ${targetNodeVersion}.`, 'succeed')
} catch (e) {
this.hbService.logger('Could not rebuild all modules - check Homebridge logs.', 'warn')
}
const npmGlobalPath = execSync('/bin/echo -n "$(npm -g prefix)/lib/node_modules"', {
env: Object.assign({
npm_config_loglevel: 'silent',
npm_update_notifier: 'false',
}, process.env),
}).toString('utf8')

execSync('npm rebuild --unsafe-perm', {
cwd: process.env.UIX_BASE_PATH,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt homebridge-config-ui-x for Node.js ${targetNodeVersion}.`, 'succeed')

if (all === true) {
// rebuild all modules
try {
execSync('npm rebuild --unsafe-perm', {
cwd: npmGlobalPath,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt plugins in ${npmGlobalPath} for Node.js ${targetNodeVersion}.`, 'succeed')
} catch (e) {
this.hbService.logger('Could not rebuild all modules - check Homebridge logs.', 'warn')
}

await this.setNpmPermissions(npmGlobalPath)
}

await this.setNpmPermissions(npmGlobalPath)
} catch (e) {
console.error(e.toString())
this.hbService.logger('ERROR: Failed Operation', 'fail')
Expand Down
61 changes: 22 additions & 39 deletions src/bin/platforms/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,46 +199,29 @@ export class LinuxInstaller extends BasePlatform {

const targetNodeVersion = execSync('node -v').toString('utf8').trim()

if (this.isPackage() && process.env.UIX_USE_PNPM === '1' && process.env.UIX_CUSTOM_PLUGIN_PATH) {
// pnpm+package mode
const cwd = dirname(process.env.UIX_CUSTOM_PLUGIN_PATH)

if (!await pathExists(cwd)) {
this.hbService.logger(`Path does not exist: "${cwd}"`, 'fail')
process.exit(1)
}
const npmGlobalPath = execSync('/bin/echo -n "$(npm -g prefix)/lib/node_modules"', {
env: Object.assign({
npm_config_loglevel: 'silent',
npm_update_notifier: 'false',
}, process.env),
}).toString('utf8')

execSync('npm rebuild --unsafe-perm', {
cwd: process.env.UIX_BASE_PATH,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt homebridge-config-ui-x for Node.js ${targetNodeVersion}.`, 'succeed')

execSync(`pnpm -C "${cwd}" rebuild`, {
cwd,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt plugins in ${process.env.UIX_CUSTOM_PLUGIN_PATH} for Node.js ${targetNodeVersion}.`, 'succeed')
} else {
// normal global npm setups
const npmGlobalPath = execSync('/bin/echo -n "$(npm -g prefix)/lib/node_modules"', {
env: Object.assign({
npm_config_loglevel: 'silent',
npm_update_notifier: 'false',
}, process.env),
}).toString('utf8')

execSync('npm rebuild --unsafe-perm', {
cwd: process.env.UIX_BASE_PATH,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt homebridge-config-ui-x for Node.js ${targetNodeVersion}.`, 'succeed')

if (all === true) {
// rebuild all global node_modules
try {
execSync('npm rebuild --unsafe-perm', {
cwd: npmGlobalPath,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt plugins in ${npmGlobalPath} for Node.js ${targetNodeVersion}.`, 'succeed')
} catch (e) {
this.hbService.logger('Could not rebuild all plugins - check logs.', 'warn')
}
if (all === true) {
// rebuild all global node_modules
try {
execSync('npm rebuild --unsafe-perm', {
cwd: npmGlobalPath,
stdio: 'inherit',
})
this.hbService.logger(`Rebuilt plugins in ${npmGlobalPath} for Node.js ${targetNodeVersion}.`, 'succeed')
} catch (e) {
this.hbService.logger('Could not rebuild all plugins - check logs.', 'warn')
}
}
} catch (e) {
Expand Down
2 changes: 0 additions & 2 deletions src/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export class ConfigService {
public enableTerminalAccess = this.runningInDocker || this.runningInSynologyPackage || this.runningInPackageMode || Boolean(process.env.HOMEBRIDGE_CONFIG_UI_TERMINAL === '1')

// plugin management
public usePnpm = (process.env.UIX_USE_PNPM === '1')
public usePluginBundles = (process.env.UIX_USE_PLUGIN_BUNDLES === '1')

// recommend child bridges on platforms with > 2GB ram
Expand Down Expand Up @@ -214,7 +213,6 @@ export class ConfigService {
customWallpaperHash: this.customWallpaperHash,
setupWizardComplete: this.setupWizardComplete,
recommendChildBridges: this.recommendChildBridges,
usePnpm: this.usePnpm,
},
formAuth: Boolean(this.ui.auth !== 'none'),
theme: this.ui.theme || 'orange',
Expand Down
17 changes: 4 additions & 13 deletions src/modules/plugins/plugins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,7 @@ export class PluginsService {
const installOptions: Array<string> = []

// check to see if custom plugin path is using a package.json file
if (
installPath === this.configService.customPluginPath
&& !(action === 'uninstall' && this.configService.usePnpm)
&& await pathExists(resolve(installPath, '../package.json'))
) {
if (installPath === this.configService.customPluginPath && await pathExists(resolve(installPath, '../package.json'))) {
installOptions.push('--save')
}

Expand Down Expand Up @@ -1174,8 +1170,8 @@ export class PluginsService {
this.logger.error('ERROR: You might be able to fix this problem by running: npm install -g npm')
}
}
// Linux and macOS don't require the full path to npm / pnpm
return this.configService.usePnpm ? ['pnpm'] : ['npm']
// Linux and macOS don't require the full path to npm
return ['npm']
}

/**
Expand Down Expand Up @@ -1399,14 +1395,9 @@ export class PluginsService {
npm_config_update_notifier: 'false',
npm_config_prefer_online: 'true',
npm_config_foreground_scripts: 'true',
npm_config_loglevel: 'error',
})

if (!this.configService.usePnpm) {
Object.assign(env, {
npm_config_loglevel: 'error',
})
}

// set global prefix for unix based systems
if (command.includes('-g') && basename(cwd) === 'lib') {
cwd = dirname(cwd)
Expand Down
15 changes: 4 additions & 11 deletions src/self-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ function tryRebuildNodePtyModule() {
logger.warn('[node-pty] Trying to rebuild automatically...')
logger.warn(`[node-pty] Path: ${modulePath}`)
try {
if (process.env.UIX_USE_PNPM === '1' && process.env.UIX_CUSTOM_PLUGIN_PATH) {
execSync('pnpm rebuild @homebridge/node-pty-prebuilt-multiarch', {
cwd: process.env.UIX_CUSTOM_PLUGIN_PATH,
stdio: 'ignore',
})
} else {
execSync('npm run install --unsafe-perm', {
cwd: modulePath,
stdio: 'ignore',
})
}
execSync('npm run install --unsafe-perm', {
cwd: modulePath,
stdio: 'ignore',
})
} catch (e) {
if (platform() !== 'win32') {
execSync('sudo -E -n run install --unsafe-perm', {
Expand Down
1 change: 0 additions & 1 deletion ui/src/app/core/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interface EnvInterface {
customWallpaperHash: string
setupWizardComplete: boolean
recommendChildBridges: boolean
usePnpm: boolean
}

interface AppSettingsInterface {
Expand Down
2 changes: 0 additions & 2 deletions ui/src/app/modules/status/status.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ <h3 class="primary-text m-0">{{ 'menu.label_status' | translate }}</h3>
</div>
<div class="row mb-auto">
<div class="col-md-12 text-center px-4 pt-1 pt-lg-2 pb-3 pb-lg-2 grey-text">
<a class="red-text" href="javascript: void(0);" (click)="openPnpmModal()" *ngIf="$settings.env.usePnpm">
<i class="fas fa-fw fa-warning"></i></a>
<!-- The below copyright notice shall be included and displayed on all copies or substantial portions of this software. -->
<small>
&copy; 2024
Expand Down
18 changes: 0 additions & 18 deletions ui/src/app/modules/status/status.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AuthService } from '@/app/core/auth/auth.service'
import { InformationComponent } from '@/app/core/components/information/information.component'
import { NotificationService } from '@/app/core/notification.service'
import { SettingsService } from '@/app/core/settings.service'
import { IoNamespace, WsService } from '@/app/core/ws.service'
Expand Down Expand Up @@ -278,23 +277,6 @@ export class StatusComponent implements OnInit, OnDestroy {
})
}

openPnpmModal() {
const ref = this.$modal.open(InformationComponent, {
size: 'lg',
backdrop: 'static',
})
ref.componentInstance.title = 'pnpm'
ref.componentInstance.subtitle = 'This warning is visible as you are using the pnpm package manager.'
ref.componentInstance.message = 'The next version of Homebridge UI will no longer support pnpm.'
+ ' You should consider updating your Homebridge instance to use npm instead.'
+ ' This can be done by following the update instructions in the Homebridge APT package documentation.'
+ ' See the link below for more information.'
ref.componentInstance.faIconClass = 'fab fa-fw fa-npm red-text'

ref.componentInstance.ctaButtonLabel = 'Update Info'
ref.componentInstance.ctaButtonLink = 'https://github.com/homebridge/homebridge-apt-pkg/blob/latest/README.md#using-apt'
}

ngOnDestroy() {
this.io.end()
this.saveWidgetsEvent.complete()
Expand Down

0 comments on commit 16b7edf

Please sign in to comment.