Skip to content

Commit af14809

Browse files
committed
fix: handle sync spawn error
Close #1438
1 parent 3347c45 commit af14809

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

packages/electron-builder-util/src/util.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface ExecOptions extends BaseExecOptions {
2929
}
3030

3131
export function removePassword(input: string) {
32-
return input.replace(/(-P |pass:| \/p|-pass )([^ ]+)/g, function (match, p1, p2) {
32+
return input.replace(/(-P |pass:| \/p |-pass )([^ ]+)/g, function (match, p1, p2) {
3333
return `${p1}${createHash("sha256").update(p2).digest("hex")} (sha256 hash)`
3434
})
3535
}
@@ -90,7 +90,13 @@ export function doSpawn(command: string, args: Array<string>, options?: SpawnOpt
9090
const argsString = args.join(" ")
9191
debug(`Spawning ${command} ${command === "docker" ? argsString : removePassword(argsString)}`)
9292
}
93-
return _spawn(command, args, options)
93+
94+
try {
95+
return _spawn(command, args, options)
96+
}
97+
catch (e) {
98+
throw new Error(`Cannot spawn ${command}: ${e.stack || e}`)
99+
}
94100
}
95101

96102
export function spawn(command: string, args?: Array<string> | null, options?: SpawnOptions): Promise<any> {

packages/electron-builder/src/yarn.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export async function rebuild(appDir: string, frameworkInfo: DesktopFrameworkInf
117117
return spawn(execPath, execArgs, {
118118
cwd: dep.path,
119119
env: env,
120-
stdio: ["pipe", process.stdout, process.stderr]
121120
})
122121
.catch(error => {
123122
if (dep.optional) {
@@ -136,7 +135,6 @@ export async function rebuild(appDir: string, frameworkInfo: DesktopFrameworkInf
136135
await spawn(execPath, execArgs, {
137136
cwd: appDir,
138137
env: env,
139-
stdio: ["pipe", process.stdout, process.stderr]
140138
})
141139
}
142140
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`remove password from log 1`] = `"seq -P 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash) -B"`;
4+
5+
exports[`remove password from log 2`] = `"pass:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash)"`;
6+
7+
exports[`remove password from log 3`] = `"/usr/bin/productbuild -P 56ef615b2e26c3b9a10dc2824238fb8b8a154ec7db4907ec6ee357ed7bb350b7 (sha256 hash)"`;
8+
9+
exports[`remove password from log 4`] = `" /p 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash)"`;

test/src/mac/CodeSignTest.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createKeychain } from "electron-builder/out/codeSign"
2-
import { CSC_LINK } from "../helpers/codeSignData"
31
import { removePassword } from "electron-builder-util"
42
import { TmpDir } from "electron-builder-util/out/tmp"
3+
import { createKeychain } from "electron-builder/out/codeSign"
4+
import { CSC_LINK } from "../helpers/codeSignData"
55

66
if (process.env.CSC_KEY_PASSWORD == null) {
77
fit("Skip keychain-specific tests because CSC_KEY_PASSWORD is not defined", () => {
@@ -22,7 +22,8 @@ test.ifMac("create keychain with installers", async () => {
2222
})
2323

2424
test.ifDevOrLinuxCi("remove password from log", async () => {
25-
expect(removePassword("seq -P foo -B")).toEqual("seq -P 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash) -B")
26-
expect(removePassword("pass:foo")).toEqual("pass:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash)")
27-
expect(removePassword("/usr/bin/productbuild -P wefwef")).toEqual("/usr/bin/productbuild -P 56ef615b2e26c3b9a10dc2824238fb8b8a154ec7db4907ec6ee357ed7bb350b7 (sha256 hash)")
25+
expect(removePassword("seq -P foo -B")).toMatchSnapshot()
26+
expect(removePassword("pass:foo")).toMatchSnapshot()
27+
expect(removePassword("/usr/bin/productbuild -P wefwef")).toMatchSnapshot()
28+
expect(removePassword(" /p foo")).toMatchSnapshot()
2829
})

test/vendor/yarn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34834,7 +34834,7 @@ Identity._oldVersionDetect = function (obj) {
3483434834
module.exports = {
3483534835
"name": "yarn",
3483634836
"installationMethod": "unknown",
34837-
"version": "0.23.1",
34837+
"version": "0.23.2",
3483834838
"license": "BSD-2-Clause",
3483934839
"preferGlobal": true,
3484034840
"description": "📦🐈 Fast, reliable, and secure dependency management.",

0 commit comments

Comments
 (0)