Skip to content

Commit

Permalink
clean up npm cache before any install/uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Feb 8, 2025
1 parent 8061488 commit f238579
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to `homebridge-config-ui-x` will be documented in this file.
### Other Changes

- append `--omit=dev` to `npm i` commands
- clean up `npm` cache before any install/uninstall

### Homebridge Dependencies

Expand Down
35 changes: 15 additions & 20 deletions src/modules/plugins/plugins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,27 +546,22 @@ export class PluginsService {
npmPluginLabel = `${pluginAction.name}@${pluginAction.version}`
}

try {
await this.runNpmCommand(
[...this.npm, action, ...installOptions, npmPluginLabel],
installPath,
client,
pluginAction.termCols,
pluginAction.termRows,
)
// Clean up the npm cache before any install or uninstall
await this.cleanNpmCache()

// Run the npm command
await this.runNpmCommand(
[...this.npm, action, ...installOptions, npmPluginLabel],
installPath,
client,
pluginAction.termCols,
pluginAction.termRows,
)

// Ensure the custom plugin dir was not deleted
await this.ensureCustomPluginDirExists()
// Ensure the custom plugin dir was not deleted
await this.ensureCustomPluginDirExists()

return true
} catch (e) {
if (pluginAction.name === this.configService.name) {
client.emit('stdout', yellow('\r\nCleaning up npm cache, please wait...\r\n'))
await this.cleanNpmCache()
client.emit('stdout', yellow(`npm cache cleared, please try updating ${this.configService.name} again.\r\n`))
}
throw e
}
return true
}

/**
Expand Down Expand Up @@ -1593,7 +1588,7 @@ export class PluginsService {
}

return new Promise((res) => {
const child = spawn(command.shift(), command)
const child = spawn(command.shift(), command, { shell: true })

child.on('exit', (code) => {
this.logger.log(`Executed npm cache clear command with exit code ${code}.`)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/server/server.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ export class ServerService {
return new Promise((res) => {
let result = false

const child = spawn(process.execPath, ['-v'])
const child = spawn(process.execPath, ['-v'], { shell: true })

child.stdout.once('data', (data) => {
result = data.toString().trim() !== process.version
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/plugins.gateway.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
import type { TestingModule } from '@nestjs/testing'

import child_process from 'node:child_process'
import { EventEmitter } from 'node:events'
import { platform } from 'node:os'
import { resolve } from 'node:path'
Expand Down Expand Up @@ -79,6 +80,7 @@ describe('PluginsGateway (e2e)', () => {

vi.spyOn(client, 'emit')
vi.spyOn(client, 'on')
vi.spyOn(child_process, 'spawn')

// Ensure config is correct
configService.ui.sudo = false
Expand Down

0 comments on commit f238579

Please sign in to comment.