Skip to content

Commit 369f1fa

Browse files
authored
fix: Add support for nested file extensions (such as .dmg.blockmap) to Keygen publisher (#6234)
Closes: #6229
1 parent 3d4c364 commit 369f1fa

File tree

10 files changed

+89
-14
lines changed

10 files changed

+89
-14
lines changed

packages/app-builder-lib/src/appInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { prerelease, SemVer } from "semver"
33
import { PlatformSpecificBuildOptions } from "./options/PlatformSpecificBuildOptions"
44
import { Packager } from "./packager"
55
import { expandMacro } from "./util/macroExpander"
6-
import { sanitizeFileName } from "./util/sanitizeFileName"
6+
import { sanitizeFileName } from "./util/filename"
77

88
// fpm bug - rpm build --description is not escaped, well... decided to replace quite to smart quote
99
// http://leancrew.com/all-this/2010/11/smart-quotes-in-javascript/

packages/app-builder-lib/src/linuxPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import FpmTarget from "./targets/fpm"
1010
import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
1111
import SnapTarget from "./targets/snap"
1212
import { createCommonTarget } from "./targets/targetFactory"
13-
import { sanitizeFileName } from "./util/sanitizeFileName"
13+
import { sanitizeFileName } from "./util/filename"
1414

1515
export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
1616
readonly executableName: string

packages/app-builder-lib/src/options/CommonWindowsInstallerConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InvalidConfigurationError, isEmptyOrSpaces } from "builder-util"
2-
import { sanitizeFileName } from "../util/sanitizeFileName"
2+
import { sanitizeFileName } from "../util/filename"
33
import { WinPackager } from "../winPackager"
44

55
export interface CommonWindowsInstallerConfiguration {

packages/app-builder-lib/src/publish/KeygenPublisher.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { ClientRequest, RequestOptions } from "http"
44
import { HttpPublisher, PublishContext } from "electron-publish"
55
import { KeygenOptions } from "builder-util-runtime/out/publishOptions"
66
import { configureRequestOptions, HttpExecutor, parseJson } from "builder-util-runtime"
7-
import * as path from "path"
7+
import { getCompleteExtname } from "../util/filename"
8+
89
export class KeygenPublisher extends HttpPublisher {
910
readonly providerName = "keygen"
1011
readonly hostname = "api.keygen.sh"
@@ -78,7 +79,7 @@ export class KeygenPublisher extends HttpPublisher {
7879
type: "release",
7980
attributes: {
8081
filename: fileName,
81-
filetype: path.extname(fileName),
82+
filetype: getCompleteExtname(fileName),
8283
filesize: dataLength,
8384
version: this.version,
8485
platform: this.info.platform,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// @ts-ignore
2+
import * as _sanitizeFileName from "sanitize-filename"
3+
import * as path from "path"
4+
5+
export function sanitizeFileName(s: string): string {
6+
return _sanitizeFileName(s)
7+
}
8+
9+
// Get the filetype from a filename. Returns a string of one or more file extensions,
10+
// e.g. .zip, .dmg, .tar.gz, .tar.bz2, .exe.blockmap. We'd normally use `path.extname()`,
11+
// but it doesn't support multiple extensions, e.g. Foo-1.0.0.dmg.blockmap should be
12+
// .dmg.blockmap, not .blockmap.
13+
export function getCompleteExtname(filename: string): string {
14+
let extname = path.extname(filename)
15+
16+
switch (extname) {
17+
// Append leading extension for blockmap filetype
18+
case ".blockmap": {
19+
extname = path.extname(filename.replace(extname, "")) + extname
20+
21+
break
22+
}
23+
// Append leading extension for known compressed tar formats
24+
case ".bz2":
25+
case ".gz":
26+
case ".lz":
27+
case ".xz":
28+
case ".7z": {
29+
const ext = path.extname(filename.replace(extname, ""))
30+
if (ext === ".tar") {
31+
extname = ext + extname
32+
}
33+
34+
break
35+
}
36+
}
37+
38+
return extname
39+
}

packages/app-builder-lib/src/util/sanitizeFileName.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/dmg-builder/src/dmg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { findIdentity, isSignAllowed } from "app-builder-lib/out/codeSign/macCod
33
import MacPackager from "app-builder-lib/out/macPackager"
44
import { createBlockmap } from "app-builder-lib/out/targets/differentialUpdateInfoBuilder"
55
import { executeAppBuilderAsJson } from "app-builder-lib/out/util/appBuilder"
6-
import { sanitizeFileName } from "app-builder-lib/out/util/sanitizeFileName"
6+
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
77
import { Arch, AsyncTaskManager, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, spawn, retry } from "builder-util"
88
import { CancellationToken } from "builder-util-runtime"
99
import { copyDir, copyFile, exists, statOrNull } from "builder-util/out/fs"

packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sanitizeFileName } from "app-builder-lib/out/util/sanitizeFileName"
1+
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
22
import { InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
33
import { getBinFromUrl } from "app-builder-lib/out/binDownload"
44
import { Arch, getArchSuffix, SquirrelWindowsOptions, Target } from "app-builder-lib"

packages/electron-builder/src/cli/create-self-signed-cert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sanitizeFileName } from "app-builder-lib/out/util/sanitizeFileName"
1+
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
22
import { exec, log, spawn, TmpDir } from "builder-util"
33
import { unlinkIfExists } from "builder-util/out/fs"
44
import * as chalk from "chalk"

test/src/filenameUtilTest.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { getCompleteExtname } from "app-builder-lib/out/util/filename"
2+
3+
// [inputFilename, expectedExtname]
4+
const tests = [
5+
["Foo-v1.exe.blockmap", ".exe.blockmap"],
6+
["Foo-1.0.0.dmg.blockmap", ".dmg.blockmap"],
7+
["Foo-v1.0.0.exe.blockmap", ".exe.blockmap"],
8+
["Foo-1.0.0-mac.zip.blockmap", ".zip.blockmap"],
9+
["Foo-1.0.0.exe", ".exe"],
10+
["foo-1.0.0.exe", ".exe"],
11+
["foo.bar-1.0.0.dmg", ".dmg"],
12+
["Foo-2.0.0.rc1.dmg", ".dmg"],
13+
["Foo-1.0.0-mac.dmg", ".dmg"],
14+
["Foo-v1.0.0.zip", ".zip"],
15+
["Foo-1.0.0.tar.gz", ".tar.gz"],
16+
["Foo-1.0.0.tar.7z", ".tar.7z"],
17+
["Foo-1.0.0.7z", ".7z"],
18+
["Foo-1.0.0.test.7z", ".7z"],
19+
["Foo-1.0.0.tar.xz", ".tar.xz"],
20+
["Foo-1.0.0.tar.lz", ".tar.lz"],
21+
["Foo-1.0.0.tar.bz2", ".tar.bz2"],
22+
["Foo.v2.tar.bz2", ".tar.bz2"],
23+
["Foo-v1.0.0.tar.bz2", ".tar.bz2"],
24+
["Application.test.dmg", ".dmg"],
25+
["Program.1.0.0.beta1.exe", ".exe"],
26+
["application.dmg", ".dmg"],
27+
["latest.yml", ".yml"],
28+
[".gitignore", ""],
29+
[".config.yml", ".yml"],
30+
["code.h", ".h"],
31+
]
32+
33+
describe("getCompleteExtname", () => {
34+
for (const [filename, expected] of tests) {
35+
test(`get complete extname for ${filename}`, () => {
36+
const extname = getCompleteExtname(filename)
37+
38+
expect(extname).toBe(expected)
39+
})
40+
}
41+
})

0 commit comments

Comments
 (0)