-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add support for nested file extensions (such as
.dmg.blockmap
)…
- Loading branch information
Showing
10 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/app-builder-lib/src/options/CommonWindowsInstallerConfiguration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/electron-builder-squirrel-windows/src/SquirrelWindowsTarget.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
}) |