Skip to content

Commit

Permalink
fix: handle sync spawn error
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Apr 16, 2017
1 parent 3347c45 commit af14809
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
10 changes: 8 additions & 2 deletions packages/electron-builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface ExecOptions extends BaseExecOptions {
}

export function removePassword(input: string) {
return input.replace(/(-P |pass:| \/p|-pass )([^ ]+)/g, function (match, p1, p2) {
return input.replace(/(-P |pass:| \/p |-pass )([^ ]+)/g, function (match, p1, p2) {
return `${p1}${createHash("sha256").update(p2).digest("hex")} (sha256 hash)`
})
}
Expand Down Expand Up @@ -90,7 +90,13 @@ export function doSpawn(command: string, args: Array<string>, options?: SpawnOpt
const argsString = args.join(" ")
debug(`Spawning ${command} ${command === "docker" ? argsString : removePassword(argsString)}`)
}
return _spawn(command, args, options)

try {
return _spawn(command, args, options)
}
catch (e) {
throw new Error(`Cannot spawn ${command}: ${e.stack || e}`)
}
}

export function spawn(command: string, args?: Array<string> | null, options?: SpawnOptions): Promise<any> {
Expand Down
2 changes: 0 additions & 2 deletions packages/electron-builder/src/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export async function rebuild(appDir: string, frameworkInfo: DesktopFrameworkInf
return spawn(execPath, execArgs, {
cwd: dep.path,
env: env,
stdio: ["pipe", process.stdout, process.stderr]
})
.catch(error => {
if (dep.optional) {
Expand All @@ -136,7 +135,6 @@ export async function rebuild(appDir: string, frameworkInfo: DesktopFrameworkInf
await spawn(execPath, execArgs, {
cwd: appDir,
env: env,
stdio: ["pipe", process.stdout, process.stderr]
})
}
}
9 changes: 9 additions & 0 deletions test/out/mac/__snapshots__/CodeSignTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`remove password from log 1`] = `"seq -P 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash) -B"`;

exports[`remove password from log 2`] = `"pass:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash)"`;

exports[`remove password from log 3`] = `"/usr/bin/productbuild -P 56ef615b2e26c3b9a10dc2824238fb8b8a154ec7db4907ec6ee357ed7bb350b7 (sha256 hash)"`;

exports[`remove password from log 4`] = `" /p 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash)"`;
11 changes: 6 additions & 5 deletions test/src/mac/CodeSignTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createKeychain } from "electron-builder/out/codeSign"
import { CSC_LINK } from "../helpers/codeSignData"
import { removePassword } from "electron-builder-util"
import { TmpDir } from "electron-builder-util/out/tmp"
import { createKeychain } from "electron-builder/out/codeSign"
import { CSC_LINK } from "../helpers/codeSignData"

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

test.ifDevOrLinuxCi("remove password from log", async () => {
expect(removePassword("seq -P foo -B")).toEqual("seq -P 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash) -B")
expect(removePassword("pass:foo")).toEqual("pass:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae (sha256 hash)")
expect(removePassword("/usr/bin/productbuild -P wefwef")).toEqual("/usr/bin/productbuild -P 56ef615b2e26c3b9a10dc2824238fb8b8a154ec7db4907ec6ee357ed7bb350b7 (sha256 hash)")
expect(removePassword("seq -P foo -B")).toMatchSnapshot()
expect(removePassword("pass:foo")).toMatchSnapshot()
expect(removePassword("/usr/bin/productbuild -P wefwef")).toMatchSnapshot()
expect(removePassword(" /p foo")).toMatchSnapshot()
})
2 changes: 1 addition & 1 deletion test/vendor/yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -34834,7 +34834,7 @@ Identity._oldVersionDetect = function (obj) {
module.exports = {
"name": "yarn",
"installationMethod": "unknown",
"version": "0.23.1",
"version": "0.23.2",
"license": "BSD-2-Clause",
"preferGlobal": true,
"description": "📦🐈 Fast, reliable, and secure dependency management.",
Expand Down

0 comments on commit af14809

Please sign in to comment.