Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add support for multiple extensions to Keygen publisher #6234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { prerelease, SemVer } from "semver"
import { PlatformSpecificBuildOptions } from "./options/PlatformSpecificBuildOptions"
import { Packager } from "./packager"
import { expandMacro } from "./util/macroExpander"
import { sanitizeFileName } from "./util/sanitizeFileName"
import { sanitizeFileName } from "./util/filename"

// fpm bug - rpm build --description is not escaped, well... decided to replace quite to smart quote
// http://leancrew.com/all-this/2010/11/smart-quotes-in-javascript/
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import FpmTarget from "./targets/fpm"
import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
import SnapTarget from "./targets/snap"
import { createCommonTarget } from "./targets/targetFactory"
import { sanitizeFileName } from "./util/sanitizeFileName"
import { sanitizeFileName } from "./util/filename"

export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
readonly executableName: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InvalidConfigurationError, isEmptyOrSpaces } from "builder-util"
import { sanitizeFileName } from "../util/sanitizeFileName"
import { sanitizeFileName } from "../util/filename"
import { WinPackager } from "../winPackager"

export interface CommonWindowsInstallerConfiguration {
Expand Down
5 changes: 3 additions & 2 deletions packages/app-builder-lib/src/publish/KeygenPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ClientRequest, RequestOptions } from "http"
import { HttpPublisher, PublishContext } from "electron-publish"
import { KeygenOptions } from "builder-util-runtime/out/publishOptions"
import { configureRequestOptions, HttpExecutor, parseJson } from "builder-util-runtime"
import * as path from "path"
import { getCompleteExtname } from "../util/filename"

export class KeygenPublisher extends HttpPublisher {
readonly providerName = "keygen"
readonly hostname = "api.keygen.sh"
Expand Down Expand Up @@ -78,7 +79,7 @@ export class KeygenPublisher extends HttpPublisher {
type: "release",
attributes: {
filename: fileName,
filetype: path.extname(fileName),
filetype: getCompleteExtname(fileName),
filesize: dataLength,
version: this.version,
platform: this.info.platform,
Expand Down
39 changes: 39 additions & 0 deletions packages/app-builder-lib/src/util/filename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @ts-ignore
import * as _sanitizeFileName from "sanitize-filename"
import * as path from "path"

export function sanitizeFileName(s: string): string {
Copy link
Contributor Author

@ezekg ezekg Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting that renaming this file may be a breaking change if anybody is relying on util/sanitizeFileName. I assume it's meant to be internal, but ya know.

return _sanitizeFileName(s)
}

// Get the filetype from a filename. Returns a string of one or more file extensions,
// e.g. .zip, .dmg, .tar.gz, .tar.bz2, .exe.blockmap. We'd normally use `path.extname()`,
// but it doesn't support multiple extensions, e.g. Foo-1.0.0.dmg.blockmap should be
// .dmg.blockmap, not .blockmap.
export function getCompleteExtname(filename: string): string {
let extname = path.extname(filename)

switch (extname) {
// Append leading extension for blockmap filetype
case ".blockmap": {
extname = path.extname(filename.replace(extname, "")) + extname

break
}
// Append leading extension for known compressed tar formats
case ".bz2":
case ".gz":
case ".lz":
case ".xz":
case ".7z": {
const ext = path.extname(filename.replace(extname, ""))
if (ext === ".tar") {
extname = ext + extname
}

break
}
}

return extname
}
6 changes: 0 additions & 6 deletions packages/app-builder-lib/src/util/sanitizeFileName.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/dmg-builder/src/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { findIdentity, isSignAllowed } from "app-builder-lib/out/codeSign/macCod
import MacPackager from "app-builder-lib/out/macPackager"
import { createBlockmap } from "app-builder-lib/out/targets/differentialUpdateInfoBuilder"
import { executeAppBuilderAsJson } from "app-builder-lib/out/util/appBuilder"
import { sanitizeFileName } from "app-builder-lib/out/util/sanitizeFileName"
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
import { Arch, AsyncTaskManager, exec, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, spawn, retry } from "builder-util"
import { CancellationToken } from "builder-util-runtime"
import { copyDir, copyFile, exists, statOrNull } from "builder-util/out/fs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sanitizeFileName } from "app-builder-lib/out/util/sanitizeFileName"
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
import { InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
import { getBinFromUrl } from "app-builder-lib/out/binDownload"
import { Arch, getArchSuffix, SquirrelWindowsOptions, Target } from "app-builder-lib"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sanitizeFileName } from "app-builder-lib/out/util/sanitizeFileName"
import { sanitizeFileName } from "app-builder-lib/out/util/filename"
import { exec, log, spawn, TmpDir } from "builder-util"
import { unlinkIfExists } from "builder-util/out/fs"
import * as chalk from "chalk"
Expand Down
41 changes: 41 additions & 0 deletions test/src/filenameUtilTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getCompleteExtname } from "app-builder-lib/out/util/filename"

// [inputFilename, expectedExtname]
const tests = [
["Foo-v1.exe.blockmap", ".exe.blockmap"],
["Foo-1.0.0.dmg.blockmap", ".dmg.blockmap"],
["Foo-v1.0.0.exe.blockmap", ".exe.blockmap"],
["Foo-1.0.0-mac.zip.blockmap", ".zip.blockmap"],
["Foo-1.0.0.exe", ".exe"],
["foo-1.0.0.exe", ".exe"],
["foo.bar-1.0.0.dmg", ".dmg"],
["Foo-2.0.0.rc1.dmg", ".dmg"],
["Foo-1.0.0-mac.dmg", ".dmg"],
["Foo-v1.0.0.zip", ".zip"],
["Foo-1.0.0.tar.gz", ".tar.gz"],
["Foo-1.0.0.tar.7z", ".tar.7z"],
["Foo-1.0.0.7z", ".7z"],
["Foo-1.0.0.test.7z", ".7z"],
["Foo-1.0.0.tar.xz", ".tar.xz"],
["Foo-1.0.0.tar.lz", ".tar.lz"],
["Foo-1.0.0.tar.bz2", ".tar.bz2"],
["Foo.v2.tar.bz2", ".tar.bz2"],
["Foo-v1.0.0.tar.bz2", ".tar.bz2"],
["Application.test.dmg", ".dmg"],
["Program.1.0.0.beta1.exe", ".exe"],
["application.dmg", ".dmg"],
["latest.yml", ".yml"],
[".gitignore", ""],
[".config.yml", ".yml"],
["code.h", ".h"],
]

describe("getCompleteExtname", () => {
for (const [filename, expected] of tests) {
test(`get complete extname for ${filename}`, () => {
const extname = getCompleteExtname(filename)

expect(extname).toBe(expected)
})
}
})