Skip to content

Commit 2fa4498

Browse files
authored
Merge branch 'master' into fix/asar-symlink-check
2 parents 3468f79 + a6be444 commit 2fa4498

File tree

7 files changed

+28
-14
lines changed

7 files changed

+28
-14
lines changed

.changeset/little-pandas-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"builder-util": patch
3+
---
4+
5+
chore: wrapping Error in exec rejection so as to pass through error code to downstream logic

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ jobs:
167167
run: pnpm generate-all
168168

169169
test-windows:
170-
runs-on: windows-2019
170+
runs-on: windows-2022
171171
timeout-minutes: 20
172172
strategy:
173173
fail-fast: false

packages/builder-util/src/util.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecFi
123123
} else {
124124
const code = (error as any).code
125125
// https://github.com/npm/npm/issues/17624
126-
if ((file.toLowerCase().endsWith("npm") || file.toLowerCase().endsWith("npm.cmd")) && args?.includes("list") && args?.includes("--silent")) {
126+
if (code === 1 && (file.toLowerCase().endsWith("npm") || file.toLowerCase().endsWith("npm.cmd")) && args?.includes("list") && args?.includes("--silent")) {
127127
console.error({ file, code }, error.message)
128128
resolve(stdout.toString())
129129
return
@@ -142,7 +142,8 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecFi
142142
message += `\n${chalk.red(stderr.toString())}`
143143
}
144144

145-
reject(new Error(message))
145+
// TODO: switch to ECMA Script 2026 Error class with `cause` property to return stack trace
146+
reject(new ExecError(file, code, message, "", `${error.code || ExecError.code}`))
146147
}
147148
}
148149
)
@@ -271,12 +272,14 @@ function formatOut(text: string, title: string) {
271272
export class ExecError extends Error {
272273
alreadyLogged = false
273274

275+
static code = "ERR_ELECTRON_BUILDER_CANNOT_EXECUTE"
276+
274277
constructor(
275278
command: string,
276279
readonly exitCode: number,
277280
out: string,
278281
errorOut: string,
279-
code = "ERR_ELECTRON_BUILDER_CANNOT_EXECUTE"
282+
code = ExecError.code
280283
) {
281284
super(`${command} process failed ${code}${formatOut(String(exitCode), "Exit code")}${formatOut(out, "Output")}${formatOut(errorOut, "Error output")}`)
282285
;(this as NodeJS.ErrnoException).code = code

packages/dmg-builder/src/dmg.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as path from "path"
1212
import { TmpDir } from "temp-file"
1313
import { addLicenseToDmg } from "./dmgLicense"
1414
import { attachAndExecute, computeBackground, detach, getDmgVendorPath } from "./dmgUtil"
15-
import { hdiUtil } from "./hdiuil"
15+
import { hdiUtil, hdiutilTransientExitCodes } from "./hdiuil"
1616

1717
export class DmgTarget extends Target {
1818
readonly options: DmgOptions = this.packager.config.dmg || Object.create(null)
@@ -197,20 +197,27 @@ export class DmgTarget extends Target {
197197
}
198198

199199
async function createStageDmg(tempDmg: string, appPath: string, volumeName: string) {
200-
//noinspection SpellCheckingInspection
201-
const imageArgs = addLogLevel(["create", "-srcfolder", appPath, "-volname", volumeName, "-anyowners", "-nospotlight", "-format", "UDRW"])
200+
const createArgs = ["create", "-srcfolder", appPath, "-volname", volumeName, "-anyowners", "-nospotlight", "-format", "UDRW"]
201+
const imageArgs = addLogLevel(createArgs)
202202
if (log.isDebugEnabled) {
203203
imageArgs.push("-debug")
204204
}
205205

206206
imageArgs.push("-fs", "APFS")
207207
imageArgs.push(tempDmg)
208-
await hdiUtil(imageArgs)
208+
await hdiUtil(imageArgs).catch(async e => {
209+
if (hdiutilTransientExitCodes.has(e.code)) {
210+
// Delay then create, then retry with verbose output
211+
await new Promise(resolve => setTimeout(resolve, 3000))
212+
return hdiUtil(addLogLevel(createArgs, true))
213+
}
214+
throw e
215+
})
209216
return tempDmg
210217
}
211218

212-
function addLogLevel(args: Array<string>): Array<string> {
213-
args.push(process.env.DEBUG_DMG === "true" ? "-verbose" : "-quiet")
219+
function addLogLevel(args: Array<string>, isVerbose = process.env.DEBUG_DMG === "true"): Array<string> {
220+
args.push(isVerbose ? "-verbose" : "-quiet")
214221
return args
215222
}
216223

packages/dmg-builder/src/dmgUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function detach(name: string) {
3838
if (hdiutilTransientExitCodes.has(e.code)) {
3939
// Delay then force unmount with verbose output
4040
await new Promise(resolve => setTimeout(resolve, 3000))
41-
return hdiUtil(["detach", "--force", name])
41+
return hdiUtil(["detach", "-force", name])
4242
}
4343
throw e
4444
})

test/src/helpers/updaterTestUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NodeHttpExecutor, serializeToYaml, TmpDir } from "builder-util"
22
import { AllPublishOptions, DownloadOptions } from "builder-util-runtime"
33
import { AppUpdater, MacUpdater, NsisUpdater } from "electron-updater"
4-
import { TestOnlyUpdaterOptions } from "electron-updater/out/AppUpdater"
4+
import { NoOpLogger, TestOnlyUpdaterOptions } from "electron-updater/out/AppUpdater"
55
import { outputFile, writeFile } from "fs-extra"
66
import * as path from "path"
77
import { assertThat } from "./fileAssert"
@@ -75,7 +75,7 @@ export function tuneTestUpdater(updater: AppUpdater, options?: TestOnlyUpdaterOp
7575
platform: "win32",
7676
...options,
7777
}
78-
updater.logger = console
78+
updater.logger = new NoOpLogger()
7979
}
8080

8181
export function trackEvents(updater: AppUpdater) {

test/src/updater/differentialUpdateTest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ async function testBlockMap(expect: ExpectStatic, oldDir: string, newDir: string
211211
platform: platform.nodeName as any,
212212
isUseDifferentialDownload: true,
213213
})
214-
updater.logger = console
215214

216215
const currentUpdaterCacheDirName = (await updater.configOnDisk.value).updaterCacheDirName
217216
if (currentUpdaterCacheDirName == null) {

0 commit comments

Comments
 (0)