diff --git a/packages/electron-builder-http/src/updateInfo.ts b/packages/electron-builder-http/src/updateInfo.ts index c06b30eac4a..823d9ba7bef 100644 --- a/packages/electron-builder-http/src/updateInfo.ts +++ b/packages/electron-builder-http/src/updateInfo.ts @@ -7,7 +7,7 @@ export interface VersionInfo { export interface UpdateInfo extends VersionInfo { readonly path: string - readonly githubArtifactName?: string | null + githubArtifactName?: string | null /** * The release name. diff --git a/packages/electron-builder/src/macPackager.ts b/packages/electron-builder/src/macPackager.ts index e87eac33cd9..08f478d757e 100644 --- a/packages/electron-builder/src/macPackager.ts +++ b/packages/electron-builder/src/macPackager.ts @@ -199,9 +199,10 @@ export default class MacPackager extends PlatformPackager { throw new Error(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`) } - const pkg = path.join(outDir!, this.expandArtifactNamePattern(masOptions, "pkg")) - await this.doFlat(appPath, pkg, masInstallerIdentity, keychainName) - this.dispatchArtifactCreated(pkg, null, Arch.x64, this.computeSafeArtifactName("pkg")) + const artifactName = this.expandArtifactNamePattern(masOptions, "pkg") + const artifactPath = path.join(outDir!, artifactName) + await this.doFlat(appPath, artifactPath, masInstallerIdentity, keychainName) + this.dispatchArtifactCreated(artifactPath, null, Arch.x64, this.computeSafeArtifactName(artifactName, "pkg")) } } diff --git a/packages/electron-builder/src/packagerApi.ts b/packages/electron-builder/src/packagerApi.ts index b180775e68f..e7e3b15f6e7 100644 --- a/packages/electron-builder/src/packagerApi.ts +++ b/packages/electron-builder/src/packagerApi.ts @@ -33,7 +33,7 @@ export interface ArtifactCreated { readonly file?: string readonly data?: Buffer - readonly safeArtifactName?: string + readonly safeArtifactName?: string | null readonly publishConfig?: PublishConfiguration diff --git a/packages/electron-builder/src/platformPackager.ts b/packages/electron-builder/src/platformPackager.ts index d9b8414bb4d..1b05e209397 100644 --- a/packages/electron-builder/src/platformPackager.ts +++ b/packages/electron-builder/src/platformPackager.ts @@ -89,7 +89,7 @@ export abstract class PlatformPackager return this.packagerOptions.prepackaged || path.join(outDir, `${this.platform.buildConfigurationKey}${getArchSuffix(arch)}${this.platform === Platform.MAC ? "" : "-unpacked"}`) } - dispatchArtifactCreated(file: string, target: Target | null, arch: Arch | null, safeArtifactName?: string) { + dispatchArtifactCreated(file: string, target: Target | null, arch: Arch | null, safeArtifactName?: string | null) { this.info.dispatchArtifactCreated({ file, safeArtifactName, target, arch, packager: this, @@ -350,7 +350,12 @@ export abstract class PlatformPackager await this.checkFileInPackage(resourcesDir, "package.json", "Application", isAsar) } - computeSafeArtifactName(ext: string, arch?: Arch | null, skipArchIfX64 = true) { + computeSafeArtifactName(suggestedName: string | null, ext: string, arch?: Arch | null, skipArchIfX64 = true): string | null { + // GitHub only allows the listed characters in file names. + if (suggestedName != null && /^[0-9A-Za-z._-]+$/.test(suggestedName)) { + return null + } + // tslint:disable:no-invalid-template-strings return this.computeArtifactName("${name}-${version}-${arch}.${ext}", ext, skipArchIfX64 && arch === Arch.x64 ? null : arch) } @@ -542,4 +547,4 @@ export abstract class PlatformPackager // remove leading dot export function normalizeExt(ext: string) { return ext.startsWith(".") ? ext.substring(1) : ext -} \ No newline at end of file +} diff --git a/packages/electron-builder/src/publish/PublishManager.ts b/packages/electron-builder/src/publish/PublishManager.ts index ce87ccc8e29..91932388b04 100644 --- a/packages/electron-builder/src/publish/PublishManager.ts +++ b/packages/electron-builder/src/publish/PublishManager.ts @@ -160,7 +160,7 @@ export class PublishManager implements PublishContext { private getOrCreatePublisher(publishConfig: PublishConfiguration, platformPackager: PlatformPackager, target: Target | null): Publisher | null { let providerCacheKey = `${publishConfig.provider}-${platformPackager.platform.name}` - if (target) { + if (target != null) { providerCacheKey += `-${target.name}` } @@ -281,9 +281,13 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array) => makeAppXArgs.push(...it)) // wine supports only ia32 binary in any case makeappx crashed on wine await spawn(path.join(vendorPath, "windows-10", Arch[arch], "makeappx.exe"), makeAppXArgs, undefined, {isDebugEnabled: debug.enabled}) - await packager.sign(destination) + await packager.sign(artifactPath) packager.info.dispatchArtifactCreated({ - file: destination, + file: artifactPath, packager, arch, - safeArtifactName: packager.computeSafeArtifactName("appx"), + safeArtifactName: packager.computeSafeArtifactName(artifactName, "appx"), target: this, isWriteUpdateInfo: this.options.electronUpdaterAware, }) diff --git a/packages/electron-builder/src/targets/dmg.ts b/packages/electron-builder/src/targets/dmg.ts index 842a672cb55..41696752948 100644 --- a/packages/electron-builder/src/targets/dmg.ts +++ b/packages/electron-builder/src/targets/dmg.ts @@ -163,7 +163,8 @@ export class DmgTarget extends Target { return } - const artifactPath = path.join(this.outDir, packager.expandArtifactNamePattern(packager.config.dmg, "dmg")) + const artifactName = packager.expandArtifactNamePattern(packager.config.dmg, "dmg") + const artifactPath = path.join(this.outDir, artifactName) // dmg file must not exist otherwise hdiutil failed (https://github.com/electron-userland/electron-builder/issues/1308#issuecomment-282847594), so, -ov must be specified //noinspection SpellCheckingInspection @@ -176,7 +177,7 @@ export class DmgTarget extends Target { await addLicenseToDmg(packager, artifactPath) - this.packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName("dmg")) + this.packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, "dmg")) } computeVolumeName(custom?: string | null): string { diff --git a/packages/electron-builder/src/targets/pkg.ts b/packages/electron-builder/src/targets/pkg.ts index 76d22a1606a..1161b03a8e6 100644 --- a/packages/electron-builder/src/targets/pkg.ts +++ b/packages/electron-builder/src/targets/pkg.ts @@ -47,17 +47,18 @@ export class PkgTarget extends Target { throw new Error(`Cannot find valid "${certType}" to sign standalone installer, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`) } - const outFile = path.join(appOutDir, packager.expandArtifactNamePattern(options, "pkg")) + const artifactName = packager.expandArtifactNamePattern(options, "pkg") + const artifactPath = path.join(appOutDir, artifactName) const args = prepareProductBuildArgs(identity, keychainName) args.push("--distribution", distInfoFile) - args.push(outFile) + args.push(artifactPath) use(options.productbuild, it => args.push(...it as any)) await exec("productbuild", args, { cwd: appOutDir, }) await BluebirdPromise.all([unlink(innerPackageFile), unlink(distInfoFile)]) - packager.dispatchArtifactCreated(outFile, this, arch, packager.computeSafeArtifactName("pkg", arch)) + packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, "pkg", arch)) } private async customizeDistributionConfiguration(distInfoFile: string, appPath: string) { diff --git a/packages/electron-publish/src/publisher.ts b/packages/electron-publish/src/publisher.ts index f7168d23554..eb4642f334f 100644 --- a/packages/electron-publish/src/publisher.ts +++ b/packages/electron-publish/src/publisher.ts @@ -32,7 +32,7 @@ export abstract class Publisher { abstract get providerName(): string - abstract upload(file: string, arch: Arch, safeArtifactName?: string): Promise + abstract upload(file: string, arch: Arch, safeArtifactName?: string | null): Promise protected createProgressBar(fileName: string, fileStat: Stats): ProgressBar | null { if (this.context.progress == null) { diff --git a/test/out/__snapshots__/ExtraBuildTest.js.snap b/test/out/__snapshots__/ExtraBuildTest.js.snap index d77eee865d9..90d9535b529 100644 --- a/test/out/__snapshots__/ExtraBuildTest.js.snap +++ b/test/out/__snapshots__/ExtraBuildTest.js.snap @@ -6,7 +6,6 @@ Object { Object { "arch": "x64", "file": "TestApp-1.1.0-x86_64.AppImage", - "safeArtifactName": "TestApp-1.1.0-x86_64.AppImage", }, ], } @@ -97,7 +96,7 @@ Object { `; exports[`scheme validation 1`] = ` -"Config is invalid: +"Configuration is invalid: { \\"foo\\": \\"Unknown option\\", \\"mac\\": [ @@ -136,7 +135,6 @@ Object { Object { "arch": "x64", "file": "TestApp-1.1.0-x86_64.AppImage", - "safeArtifactName": "TestApp-1.1.0-x86_64.AppImage", }, Object { "arch": "ia32", diff --git a/test/out/linux/__snapshots__/linuxPackagerTest.js.snap b/test/out/linux/__snapshots__/linuxPackagerTest.js.snap index 094cb4bbb9e..00c353dc7f5 100644 --- a/test/out/linux/__snapshots__/linuxPackagerTest.js.snap +++ b/test/out/linux/__snapshots__/linuxPackagerTest.js.snap @@ -31,7 +31,6 @@ Object { Object { "arch": "x64", "file": "TestApp-1.1.0-x86_64.AppImage", - "safeArtifactName": "TestApp-1.1.0-x86_64.AppImage", }, ], } @@ -43,7 +42,6 @@ Object { Object { "arch": "x64", "file": "TestApp-1.1.0-x86_64.AppImage", - "safeArtifactName": "TestApp-1.1.0-x86_64.AppImage", }, ], } diff --git a/test/out/mac/__snapshots__/dmgTest.js.snap b/test/out/mac/__snapshots__/dmgTest.js.snap index f9be54d84e1..1c07539c96d 100644 --- a/test/out/mac/__snapshots__/dmgTest.js.snap +++ b/test/out/mac/__snapshots__/dmgTest.js.snap @@ -81,7 +81,6 @@ Object { Object { "arch": "x64", "file": "NoApplicationsLink-1.1.0.dmg", - "safeArtifactName": "TestApp-1.1.0.dmg", }, Object { "arch": "x64", @@ -98,7 +97,6 @@ Object { Object { "arch": "x64", "file": "NoBackground-1.1.0.dmg", - "safeArtifactName": "TestApp-1.1.0.dmg", }, ], } @@ -112,7 +110,6 @@ Object { Object { "arch": "x64", "file": "NoBuildDirectory-1.1.0.dmg", - "safeArtifactName": "TestApp-1.1.0.dmg", }, ], } diff --git a/test/out/mac/__snapshots__/macPackagerTest.js.snap b/test/out/mac/__snapshots__/macPackagerTest.js.snap index 72f410be645..8533c770150 100644 --- a/test/out/mac/__snapshots__/macPackagerTest.js.snap +++ b/test/out/mac/__snapshots__/macPackagerTest.js.snap @@ -97,7 +97,6 @@ Object { Object { "arch": "x64", "file": "TestApp-1.1.0-mac.dmg", - "safeArtifactName": "TestApp-1.1.0.dmg", }, Object { "file": "latest-mac.json",