Skip to content

Commit 521aea6

Browse files
MariaDimadevelar
authored andcommitted
feat: local path to custom electron build (windows support)
Close #1534, Close #1342
1 parent d8aa078 commit 521aea6

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

packages/electron-builder/src/macPackager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,12 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
245245
args.push(outFile)
246246
return await exec("productbuild", args)
247247
}
248+
249+
public getElectronSrcDir(dist: string) {
250+
return path.resolve(this.projectDir, dist, this.electronDistMacOsAppName)
251+
}
252+
253+
public getElectronDestDir(appOutDir: string) {
254+
return path.join(appOutDir, this.electronDistMacOsAppName)
255+
}
248256
}

packages/electron-builder/src/packager/dirPackager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { path7za } from "7zip-bin"
22
import BluebirdPromise from "bluebird-lst"
33
import { debug7zArgs, spawn } from "electron-builder-util"
44
import { copyDir } from "electron-builder-util/out/fs"
5-
import { warn } from "electron-builder-util/out/log"
5+
import { log, warn } from "electron-builder-util/out/log"
66
import { chmod, emptyDir } from "fs-extra-p"
77
import * as path from "path"
88
import { PlatformPackager } from "../platformPackager"
@@ -55,8 +55,11 @@ async function unpack(packager: PlatformPackager<any>, out: string, platform: st
5555
await spawn(path7za, debug7zArgs("x").concat(zipPath, `-o${out}`))
5656
}
5757
else {
58+
const source = packager.getElectronSrcDir(dist)
59+
const destination = packager.getElectronDestDir(out)
60+
log(`Copying Electron from "${source}" to "${destination}"`)
5861
await emptyDir(out)
59-
await copyDir(path.resolve(packager.info.projectDir, dist, "Electron.app"), path.join(out, "Electron.app"))
62+
await copyDir(source, destination)
6063
}
6164

6265
if (platform === "linux") {

packages/electron-builder/src/platformPackager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
272272
return deepAssign({}, result)
273273
}
274274

275+
public getElectronSrcDir(dist: string): string {
276+
return path.resolve(this.projectDir, dist)
277+
}
278+
279+
public getElectronDestDir(appOutDir: string): string {
280+
return appOutDir
281+
}
282+
275283
public getResourcesDir(appOutDir: string): string {
276284
return this.platform === Platform.MAC ? this.getMacOsResourcesDir(appOutDir) : path.join(appOutDir, "resources")
277285
}

test/out/windows/__snapshots__/winPackagerTest.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ exports[`icon not an image 1`] = `"Windows icon is not valid ico file, please fi
66
77
exports[`sign certificateSha1 1`] = `"certificateSha1 supported only on Windows"`;
88
9+
exports[`sign electronDist 1`] = `"ENOENT: no such file or directory, scandir '<path>/foo'"`;
10+
911
exports[`sign ev 1`] = `"certificateSubjectName supported only on Windows"`;
1012
1113
exports[`sign forceCodeSigning 1`] = `"App is not signed and \\"forceCodeSigning\\" is set to true, please ensure that code signing configuration is correct, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing"`;

test/src/windows/winPackagerTest.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Platform } from "electron-builder"
1+
import { DIR_TARGET, Platform } from "electron-builder"
22
import { rename, unlink, writeFile } from "fs-extra-p"
33
import * as path from "path"
44
import { CheckingWinPackager } from "../helpers/CheckingPackager"
@@ -69,4 +69,11 @@ describe.ifAll("sign", () => {
6969
forceCodeSigning: true,
7070
}
7171
}))
72+
73+
test.ifNotCiMac("electronDist", appThrows({
74+
targets: Platform.WINDOWS.createTarget(DIR_TARGET),
75+
config: {
76+
electronDist: "foo",
77+
}
78+
}))
7279
})

0 commit comments

Comments
 (0)