Skip to content

Commit

Permalink
fix: NsisUpdater - only resolving true if pid !== undefined (#7503)
Browse files Browse the repository at this point in the history
Fixes: #7502
  • Loading branch information
mmaietta committed Mar 26, 2023
1 parent 2602331 commit a2ab1ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-terms-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix: NsisUpdater - only resolving true if pid !== undefined
5 changes: 3 additions & 2 deletions packages/electron-updater/src/AppImageUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export class AppImageUpdater extends BaseUpdater {
this.emit("appimage-filename-updated", destination)
}

const env: any = {
const env: NodeJS.ProcessEnv = {
...process.env,
APPIMAGE_SILENT_INSTALL: "true",
}

Expand All @@ -107,7 +108,7 @@ export class AppImageUpdater extends BaseUpdater {
this.spawnLog(destination, [], env)
} else {
env.APPIMAGE_EXIT_AFTER_INSTALL = "true"
execFileSync(destination, [], env)
execFileSync(destination, [], { env })
}
return true
}
Expand Down
15 changes: 7 additions & 8 deletions packages/electron-updater/src/BaseUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AllPublishOptions } from "builder-util-runtime"
import { spawn, spawnSync } from "child_process"
import { spawn, SpawnOptions, spawnSync, StdioOptions } from "child_process"
import { AppAdapter } from "./AppAdapter"
import { AppUpdater, DownloadExecutorTask } from "./AppUpdater"

Expand Down Expand Up @@ -134,20 +134,19 @@ export abstract class BaseUpdater extends AppUpdater {
*/
// https://github.com/electron-userland/electron-builder/issues/1129
// Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors
protected async spawnLog(cmd: string, args: string[] = [], env: any = {}): Promise<boolean> {
protected async spawnLog(cmd: string, args: string[] = [], env: any = undefined, stdio: StdioOptions = "ignore"): Promise<boolean> {
this._logger.info(`Executing: ${cmd} with args: ${args}`)
return new Promise<boolean>((resolve, reject) => {
try {
const p = spawn(cmd, args, {
stdio: "inherit",
env: { ...process.env, ...env },
detached: true,
})
const params: SpawnOptions = { stdio, env, detached: true }
const p = spawn(cmd, args, params)
p.on("error", error => {
reject(error)
})
p.unref()
resolve(p.pid !== undefined)
if (process.pid !== undefined) {
resolve(true)
}
} catch (error) {
reject(error)
}
Expand Down

0 comments on commit a2ab1ff

Please sign in to comment.