From 3f6f5b6d82118c2c4ee084c49711c543fd3c2308 Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 6 Mar 2018 08:41:13 +0100 Subject: [PATCH] fix: snap packages don't follow artifactName Close #2576 --- .../electron-builder-lib/src/platformPackager.ts | 4 ++-- packages/electron-builder-lib/src/targets/snap.ts | 13 +++++++------ test/out/linux/__snapshots__/snapTest.js.snap | 2 +- test/src/linux/snapTest.ts | 4 ++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/electron-builder-lib/src/platformPackager.ts b/packages/electron-builder-lib/src/platformPackager.ts index f64bd0905e6..d29d951d4db 100644 --- a/packages/electron-builder-lib/src/platformPackager.ts +++ b/packages/electron-builder-lib/src/platformPackager.ts @@ -399,12 +399,12 @@ export abstract class PlatformPackager if (ext === "AppImage" || ext === "rpm") { archName = "x86_64" } - else if (ext === "deb") { + else if (ext === "deb" || ext === "snap") { archName = "amd64" } } else if (arch === Arch.ia32) { - if (ext === "deb" || ext === "AppImage") { + if (ext === "deb" || ext === "AppImage" || ext === "snap") { archName = "i386" } else if (ext === "pacman" || ext === "rpm") { diff --git a/packages/electron-builder-lib/src/targets/snap.ts b/packages/electron-builder-lib/src/targets/snap.ts index ad3c9b7abc2..aa5e8c689a8 100644 --- a/packages/electron-builder-lib/src/targets/snap.ts +++ b/packages/electron-builder-lib/src/targets/snap.ts @@ -30,8 +30,9 @@ export default class SnapTarget extends Target { return result } - private createDescriptor(snapName: string, arch: Arch): any { + private createDescriptor(arch: Arch): any { const appInfo = this.packager.appInfo + const snapName = this.packager.executableName.toLowerCase() const options = this.options const linuxArchName = toAppImageOrSnapArch(arch) @@ -109,12 +110,12 @@ export default class SnapTarget extends Target { async build(appOutDir: string, arch: Arch): Promise { const packager = this.packager const options = this.options - const snapName = packager.executableName.toLowerCase() - const snapFileName = `${snapName}_${packager.appInfo.version}_${toLinuxArchString(arch)}.snap` - const artifactPath = path.join(this.outDir, snapFileName) + // tslint:disable-next-line:no-invalid-template-strings + const artifactName = packager.expandArtifactNamePattern(this.options, "snap", arch, "${name}_${version}_${arch}.${ext}", false) + const artifactPath = path.join(this.outDir, artifactName) this.logBuilding("snap", artifactPath, arch) - const snap: any = this.createDescriptor(snapName, arch) + const snap: any = this.createDescriptor(arch) if (this.isUseTemplateApp) { delete snap.parts } @@ -166,7 +167,7 @@ export default class SnapTarget extends Target { args.push("--template-url", this.packager.isElectron2 ? "electron2" : "electron1") } await executeAppBuilder(args) - packager.dispatchArtifactCreated(artifactPath, this, arch) + packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, "snap", arch, false)) } } diff --git a/test/out/linux/__snapshots__/snapTest.js.snap b/test/out/linux/__snapshots__/snapTest.js.snap index eb4b79cd036..c49b926177b 100644 --- a/test/out/linux/__snapshots__/snapTest.js.snap +++ b/test/out/linux/__snapshots__/snapTest.js.snap @@ -509,7 +509,7 @@ Object { "linux": Array [ Object { "arch": "x64", - "file": "sep-electron2_1.1.0_amd64.snap", + "file": "sep-electron2_v1.1.0.snap", }, ], } diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index 4c32ce87f28..6644b11e3c9 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -25,6 +25,10 @@ test.ifAll.ifDevOrLinuxCi("snap electron 2", app({ extraMetadata: { name: "sep-electron2", }, + linux: { + //tslint:disable-next-line:no-invalid-template-strings + artifactName: "${name}_v${version}.${ext}", + }, productName: "Sep Electron 2", electronVersion: "2.0.0-beta.1", },