Skip to content

Commit 678d4c5

Browse files
committed
fix: make error output in case of app-builder failure more clear
1 parent f0fd512 commit 678d4c5

File tree

12 files changed

+721
-213
lines changed

12 files changed

+721
-213
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"////": "All typings are added into root `package.json` to avoid duplication errors in the IDE compiler (several `node.d.ts` files).",
3030
"dependencies": {
3131
"7zip-bin": "~3.1.0",
32-
"app-builder-bin": "1.3.1",
32+
"app-builder-bin": "1.3.3",
3333
"archiver": "^2.1.1",
3434
"async-exit-hook": "^2.0.1",
35-
"aws-sdk": "^2.192.0",
35+
"aws-sdk": "^2.196.0",
3636
"bluebird-lst": "^1.0.5",
3737
"chalk": "^2.3.0",
3838
"chromium-pickle-js": "^0.2.0",
@@ -94,15 +94,15 @@
9494
"gitbook-plugin-edit-link": "^2.0.2",
9595
"gitbook-plugin-github": "^2.0.0",
9696
"gitbook-plugin-github-buttons": "^3.0.0",
97-
"globby": "^7.1.1",
98-
"jest-cli": "^22.2.2",
97+
"globby": "^8.0.0",
98+
"jest-cli": "^22.3.0",
9999
"jest-junit": "^3.6.0",
100100
"jsdoc-to-markdown": "^4.0.1",
101101
"path-sort": "^0.1.0",
102102
"ts-babel": "^4.1.8",
103103
"ts-jsdoc": "^3.0.0",
104104
"tslint": "^5.9.1",
105-
"typescript": "2.7.0-rc",
105+
"typescript": "2.7.2",
106106
"v8-compile-cache": "^1.1.2",
107107
"whitespace": "^2.1.0",
108108
"worker-farm": "^1.5.2"

packages/builder-util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"out"
1212
],
1313
"dependencies": {
14-
"app-builder-bin": "1.3.1",
14+
"app-builder-bin": "1.3.3",
1515
"temp-file": "^3.1.1",
1616
"fs-extra-p": "^4.5.0",
1717
"is-ci": "^1.1.0",

packages/builder-util/src/binDownload.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { path7za } from "7zip-bin"
2-
import { appBuilderPath } from "app-builder-bin"
3-
import { spawn } from "./util"
1+
import { executeAppBuilder } from "./util"
42

53
const versionToPromise = new Map<string, Promise<string>>()
64

@@ -9,7 +7,7 @@ export function download(url: string, output: string, checksum?: string | null):
97
if (checksum != null) {
108
args.push("--sha512", checksum)
119
}
12-
return spawn(appBuilderPath, args)
10+
return executeAppBuilder(args) as Promise<any>
1311
}
1412

1513
export function getBinFromGithub(name: string, version: string, checksum: string): Promise<string> {
@@ -35,11 +33,5 @@ function doGetBin(name: string, url: string, checksum: string): Promise<string>
3533
args.push("--sha512", checksum)
3634
}
3735

38-
return spawn(appBuilderPath, args, {
39-
env: {
40-
...process.env,
41-
SZA_PATH: path7za,
42-
},
43-
stdio: ["ignore", "pipe", process.stdout]
44-
})
36+
return executeAppBuilder(args)
4537
}

packages/builder-util/src/util.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import BluebirdPromise from "bluebird-lst"
1+
import { path7za } from "7zip-bin"
2+
import { appBuilderPath } from "app-builder-bin"
23
import { safeStringifyJson } from "builder-util-runtime"
34
import chalk from "chalk"
45
import { ChildProcess, execFile, ExecFileOptions, spawn as _spawn, SpawnOptions } from "child_process"
@@ -83,7 +84,7 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecFi
8384
log.debug(logFields, "executing")
8485
}
8586

86-
return new BluebirdPromise<string>((resolve, reject) => {
87+
return new Promise<string>((resolve, reject) => {
8788
execFile(file, args, {
8889
...options,
8990
maxBuffer: 10 * 1024 * 1024,
@@ -139,6 +140,22 @@ export interface ExtraSpawnOptions {
139140
isPipeInput?: boolean
140141
}
141142

143+
function logSpawn(command: string, args: Array<string>, options: SpawnOptions) {
144+
// use general debug.enabled to log spawn, because it doesn't produce a lot of output (the only line), but important in any case
145+
if (!log.isDebugEnabled) {
146+
return
147+
}
148+
149+
const argsString = args.join(" ")
150+
const logFields: any = {
151+
command: command + " " + (command === "docker" ? argsString : removePassword(argsString)),
152+
}
153+
if (options != null && options.cwd != null) {
154+
logFields.cwd = options.cwd
155+
}
156+
log.debug(logFields, "spawning")
157+
}
158+
142159
export function doSpawn(command: string, args: Array<string>, options?: SpawnOptions, extraOptions?: ExtraSpawnOptions): ChildProcess {
143160
if (options == null) {
144161
options = {}
@@ -152,19 +169,7 @@ export function doSpawn(command: string, args: Array<string>, options?: SpawnOpt
152169
options.stdio = [extraOptions != null && extraOptions.isPipeInput ? "pipe" : "ignore", isDebugEnabled ? "inherit" : "pipe", isDebugEnabled ? "inherit" : "pipe"]
153170
}
154171

155-
// use general debug.enabled to log spawn, because it doesn't produce a lot of output (the only line), but important in any case
156-
if (log.isDebugEnabled) {
157-
const argsString = args.join(" ")
158-
const logFields: any = {
159-
command,
160-
args: command === "docker" ? argsString : removePassword(argsString),
161-
}
162-
if (options != null && options.cwd != null) {
163-
logFields.cwd = options.cwd
164-
}
165-
log.debug(logFields, "spawning")
166-
}
167-
172+
logSpawn(command, args, options)
168173
try {
169174
return _spawn(command, args, options)
170175
}
@@ -176,7 +181,7 @@ export function doSpawn(command: string, args: Array<string>, options?: SpawnOpt
176181
export function spawnAndWrite(command: string, args: Array<string>, data: string, options?: SpawnOptions, isDebugEnabled: boolean = false) {
177182
const childProcess = doSpawn(command, args, options, {isPipeInput: true, isDebugEnabled})
178183
const timeout = setTimeout(() => childProcess.kill(), 4 * 60 * 1000)
179-
return new BluebirdPromise<any>((resolve, reject) => {
184+
return new Promise<any>((resolve, reject) => {
180185
handleProcess("close", childProcess, command, false, () => {
181186
try {
182187
clearTimeout(timeout)
@@ -198,7 +203,7 @@ export function spawnAndWrite(command: string, args: Array<string>, data: string
198203
}
199204

200205
export function spawn(command: string, args?: Array<string> | null, options?: SpawnOptions, extraOptions?: ExtraSpawnOptions): Promise<any> {
201-
return new BluebirdPromise<any>((resolve, reject) => {
206+
return new Promise<any>((resolve, reject) => {
202207
const isCollectOutput = options != null && (options.stdio === "pipe" || (Array.isArray(options.stdio) && options.stdio.length === 3 && options.stdio[1] === "pipe"))
203208
handleProcess("close", doSpawn(command, args || [], options, extraOptions), command, isCollectOutput, resolve, reject)
204209
})
@@ -344,4 +349,17 @@ export class InvalidConfigurationError extends Error {
344349

345350
(this as any).code = code
346351
}
347-
}
352+
}
353+
354+
export function executeAppBuilder(args: Array<string>): Promise<string> {
355+
return new Promise<string>((resolve, reject) => {
356+
const command = appBuilderPath
357+
handleProcess("close", doSpawn(command, args, {
358+
env: {
359+
...process.env,
360+
SZA_PATH: path7za,
361+
},
362+
stdio: ["ignore", "pipe", "inherit"]
363+
}), command, true, resolve, reject)
364+
})
365+
}

packages/electron-builder-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"homepage": "https://github.com/electron-userland/electron-builder",
4343
"dependencies": {
4444
"7zip-bin": "~3.1.0",
45-
"app-builder-bin": "1.3.1",
45+
"app-builder-bin": "1.3.3",
4646
"async-exit-hook": "^2.0.1",
4747
"bluebird-lst": "^1.0.5",
4848
"chromium-pickle-js": "^0.2.0",

packages/electron-builder-lib/src/codeSign.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { appBuilderPath } from "app-builder-bin"
21
import BluebirdPromise from "bluebird-lst"
32
import { exec, InvalidConfigurationError, isEmptyOrSpaces, isEnvTrue, isMacOsSierra, isPullRequest, log, TmpDir } from "builder-util"
43
import { copyFile, statOrNull, unlinkIfExists } from "builder-util/out/fs"
@@ -107,7 +106,7 @@ export async function downloadCertificate(urlOrBase64: string, tmpDir: TmpDir, c
107106
if (isUrl || urlOrBase64.length > 2048 || urlOrBase64.endsWith("=")) {
108107
const tempFile = await tmpDir.getTempFile({suffix: ".p12"})
109108
if (isUrl) {
110-
await download(appBuilderPath, urlOrBase64, tempFile)
109+
await download(urlOrBase64, tempFile)
111110
}
112111
else {
113112
await outputFile(tempFile, Buffer.from(urlOrBase64, "base64"))
@@ -263,7 +262,7 @@ async function getValidIdentities(keychain?: string | null): Promise<Array<strin
263262
if (result == null || keychain != null) {
264263
// https://github.com/electron-userland/electron-builder/issues/481
265264
// https://github.com/electron-userland/electron-builder/issues/535
266-
result = BluebirdPromise.all<Array<string>>([
265+
result = Promise.all<Array<string>>([
267266
exec("security", addKeychain(["find-identity", "-v"]))
268267
.then(it => it.trim().split("\n").filter(it => {
269268
for (const prefix of appleCertificatePrefixes) {
@@ -353,7 +352,7 @@ export function findIdentity(certType: CertType, qualifier?: string | null, keyc
353352
return _findIdentity(certType, null, keychain)
354353
}
355354
else {
356-
return BluebirdPromise.resolve(null)
355+
return Promise.resolve(null)
357356
}
358357
}
359358
else {

packages/electron-builder-lib/src/platformPackager.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { appBuilderPath } from "app-builder-bin"
21
import BluebirdPromise from "bluebird-lst"
3-
import { Arch, asArray, AsyncTaskManager, debug, DebugLogger, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, deepAssign } from "builder-util"
2+
import { Arch, asArray, AsyncTaskManager, debug, DebugLogger, executeAppBuilder, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, deepAssign } from "builder-util"
43
import { PackageBuilder } from "builder-util/out/api"
54
import { statOrNull, unlinkIfExists } from "builder-util/out/fs"
65
import { orIfFileNotExist } from "builder-util/out/promise"
@@ -582,25 +581,18 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
582581

583582
// convert if need, validate size (it is a reason why tool is called even if file has target extension (already specified as foo.icns for example))
584583
async resolveIcon(sources: Array<string>, outputFormat: IconFormat): Promise<Array<IconInfo>> {
585-
const arg = [
584+
const args = [
586585
"icon",
587586
"--format", outputFormat,
588-
"--root", this.buildResourcesDir, "--root", this.projectDir,
587+
"--root", this.buildResourcesDir,
588+
"--root", this.projectDir,
589+
"--out", path.resolve(this.projectDir, this.config.directories!!.output!!, `.icon-${outputFormat}`),
589590
]
590591
for (const source of sources) {
591-
arg.push("--input", source)
592+
args.push("--input", source)
592593
}
593594

594-
const rawResult = await exec(appBuilderPath, arg, {
595-
cwd: this.projectDir,
596-
env: {
597-
...process.env,
598-
// command creates temp dir amd cannot delete it automatically since result files located in and it is our responsibility remove it after use,
599-
// so, we just set TMPDIR to tempDirManager.rootTempDir and tempDirManager in any case will delete rootTempDir on exit
600-
TMPDIR: await this.info.tempDirManager.rootTempDir,
601-
},
602-
})
603-
595+
const rawResult = await executeAppBuilder(args)
604596
let result: IconConvertResult
605597
try {
606598
result = JSON.parse(rawResult)

packages/electron-builder-lib/src/targets/AppImageTarget.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { path7za } from "7zip-bin"
2-
import { appBuilderPath } from "app-builder-bin"
31
import BluebirdPromise from "bluebird-lst"
4-
import { Arch, log, serializeToYaml, isEnvTrue, spawn } from "builder-util"
2+
import { Arch, serializeToYaml, executeAppBuilder } from "builder-util"
53
import { UUID } from "builder-util-runtime"
64
import { copyOrLinkFile, unlinkIfExists } from "builder-util/out/fs"
75
import * as ejs from "ejs"
@@ -13,7 +11,6 @@ import { Target } from "../core"
1311
import { LinuxPackager } from "../linuxPackager"
1412
import { getAppUpdatePublishConfiguration } from "../publish/PublishManager"
1513
import { getTemplatePath } from "../util/pathManager"
16-
import { appendBlockmap } from "./differentialUpdateInfoBuilder"
1714
import { LinuxTargetHelper } from "./LinuxTargetHelper"
1815
import { createStageDir } from "./targetUtil"
1916

@@ -83,25 +80,15 @@ export default class AppImageTarget extends Target {
8380
if (packager.compression === "maximum") {
8481
args.push("--compression", "xz")
8582
}
86-
if (log.isDebugEnabled && !isEnvTrue(process.env.ELECTRON_BUILDER_REMOVE_STAGE_EVEN_IF_DEBUG)) {
87-
args.push("--no-remove-stage")
88-
}
89-
await spawn(appBuilderPath, args, {
90-
env: {
91-
...process.env,
92-
SZA_PATH: path7za,
93-
},
94-
})
9583

96-
const updateInfo = await appendBlockmap(artifactPath)
9784
packager.info.dispatchArtifactCreated({
9885
file: artifactPath,
9986
safeArtifactName: packager.computeSafeArtifactName(artifactName, "AppImage", arch, false),
10087
target: this,
10188
arch,
10289
packager,
10390
isWriteUpdateInfo: true,
104-
updateInfo,
91+
updateInfo: JSON.parse(await executeAppBuilder(args)),
10592
})
10693
}
10794

packages/electron-builder-lib/src/targets/differentialUpdateInfoBuilder.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { appBuilderPath } from "app-builder-bin"
2-
import { exec, log } from "builder-util"
1+
import { log, executeAppBuilder } from "builder-util"
32
import { BlockMapDataHolder, PackageFileInfo } from "builder-util-runtime"
43
import * as path from "path"
54
import { Target } from "../core"
@@ -61,13 +60,13 @@ export function configureDifferentialAwareArchiveOptions(archiveOptions: Archive
6160

6261
export async function appendBlockmap(file: string): Promise<BlockMapDataHolder> {
6362
log.info({file: log.filePath(file)}, "building embedded block map")
64-
return JSON.parse(await exec(appBuilderPath, ["blockmap", "--input", file, "--compression", "deflate"]))
63+
return JSON.parse(await executeAppBuilder(["blockmap", "--input", file, "--compression", "deflate"]))
6564
}
6665

6766
export async function createBlockmap(file: string, target: Target, packager: PlatformPackager<any>, safeArtifactName: string | null): Promise<BlockMapDataHolder> {
6867
const blockMapFile = `${file}${BLOCK_MAP_FILE_SUFFIX}`
6968
log.info({blockMapFile: log.filePath(blockMapFile)}, "building block map")
70-
const updateInfo: BlockMapDataHolder = JSON.parse(await exec(appBuilderPath, ["blockmap", "--input", file, "--output", blockMapFile]))
69+
const updateInfo: BlockMapDataHolder = JSON.parse(await executeAppBuilder(["blockmap", "--input", file, "--output", blockMapFile]))
7170
packager.info.dispatchArtifactCreated({
7271
file: blockMapFile,
7372
safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${BLOCK_MAP_FILE_SUFFIX}`,

packages/electron-builder-lib/src/targets/snap.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { path7za } from "7zip-bin"
2-
import { appBuilderPath } from "app-builder-bin"
3-
import { isEnvTrue, Arch, replaceDefault as _replaceDefault, serializeToYaml, spawn, toLinuxArchString, log } from "builder-util"
1+
import { Arch, replaceDefault as _replaceDefault, serializeToYaml, executeAppBuilder, toLinuxArchString } from "builder-util"
42
import { outputFile } from "fs-extra-p"
53
import * as path from "path"
64
import { SnapOptions } from ".."
@@ -150,10 +148,6 @@ export default class SnapTarget extends Target {
150148

151149
await outputFile(path.join(snapMetaDir, this.isUseTemplateApp ? "snap.yaml" : "snapcraft.yaml"), serializeToYaml(snap))
152150

153-
if (log.isDebugEnabled && !isEnvTrue(process.env.ELECTRON_BUILDER_REMOVE_STAGE_EVEN_IF_DEBUG)) {
154-
args.push("--no-remove-stage")
155-
}
156-
157151
const hooksDir = await packager.getResource(options.hooks, "snap-hooks")
158152
if (hooksDir != null) {
159153
args.push("--hooks", hooksDir)
@@ -166,14 +160,7 @@ export default class SnapTarget extends Target {
166160
"--template-sha512", SNAP_TEMPLATE_SHA512,
167161
)
168162
}
169-
170-
await spawn(appBuilderPath, args, {
171-
env: {
172-
...process.env,
173-
SZA_PATH: path7za,
174-
},
175-
stdio: ["ignore", "inherit", "inherit"]
176-
})
163+
await executeAppBuilder(args)
177164
packager.dispatchArtifactCreated(artifactPath, this, arch)
178165
}
179166
}

0 commit comments

Comments
 (0)