Skip to content

Commit ba9e9da

Browse files
committed
feat(snap): do not all apt-get install and update if build packages already installed
So, reduce risk that build will be failed because of sudo. Yes - snapcraft can also install build packages. But at least electron-builder doesn't fail.
1 parent d8c0df0 commit ba9e9da

File tree

1 file changed

+10
-3
lines changed
  • packages/electron-builder-lib/src/targets

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Target } from "../core"
77
import { LinuxPackager } from "../linuxPackager"
88
import { LinuxTargetHelper } from "./LinuxTargetHelper"
99
import { createStageDir, StageDir } from "./targetUtil"
10+
import BluebirdPromise from "bluebird-lst"
1011

1112
// usr/share/fonts is required, cannot run otherwise
1213
const unnecessaryFiles = [
@@ -110,8 +111,14 @@ export default class SnapTarget extends Target {
110111
}
111112
else {
112113
if (options.buildPackages != null && options.buildPackages.length > 0) {
113-
await spawn("apt-get", ["-qq", "update"])
114-
await spawn("apt-get", ["-qq", "install", "--no-install-recommends"].concat(options.buildPackages))
114+
const notInstalledPackages = await BluebirdPromise.filter(options.buildPackages, (it): Promise<boolean> => {
115+
return exec("dpkg", ["-s", it])
116+
.then(result => result.includes("is not installed"))
117+
})
118+
if (notInstalledPackages.length > 0) {
119+
await spawn("apt-get", ["-qq", "update"])
120+
await spawn("apt-get", ["-qq", "install", "--no-install-recommends"].concat(notInstalledPackages))
121+
}
115122
}
116123
const spawnOptions = {
117124
cwd: stageDir.dir,
@@ -156,4 +163,4 @@ export default class SnapTarget extends Target {
156163
stdio: ["ignore", "inherit", "inherit"],
157164
})
158165
}
159-
}
166+
}

0 commit comments

Comments
 (0)