Skip to content

Commit

Permalink
fix(mac): use zip instead of 7z if name contains NFD characters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jebibot authored Dec 6, 2023
1 parent 4497e86 commit 0f43989
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-waves-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix macOS app signature when the name contains NFD-normalized characters
54 changes: 48 additions & 6 deletions packages/app-builder-lib/src/targets/archive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { path7za } from "7zip-bin"
import { debug7z, exec } from "builder-util"
import { debug7z, exec, log } from "builder-util"
import { exists, unlinkIfExists } from "builder-util/out/fs"
import { chmod, move } from "fs-extra"
import * as path from "path"
Expand Down Expand Up @@ -166,24 +166,66 @@ export function compute7zCompressArgs(format: string, options: ArchiveOptions =
return args
}

export function computeZipCompressArgs(options: ArchiveOptions = {}) {
let storeOnly = options.compression === "store"
// do not deref symlinks
const args = ["-q", "-r", "-y"]
if (debug7z.enabled) {
args.push("-v")
}

if (process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL != null) {
storeOnly = false
args.push(`-${process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL}`)
} else if (!storeOnly) {
// https://github.com/electron-userland/electron-builder/pull/3032
args.push("-" + (options.compression === "maximum" ? "9" : "7"))
}

if (options.dictSize != null) {
log.warn({ distSize: options.dictSize }, `ignoring unsupported option`)
}

// do not save extra file attributes (Extended Attributes on OS/2, uid/gid and file times on Unix)
if (!options.isRegularFile) {
args.push("-X")
}

if (options.method != null) {
if (options.method !== "DEFAULT") {
log.warn({ method: options.method }, `ignoring unsupported option`)
}
} else {
args.push("-Z", storeOnly ? "store" : "deflate")
}
return args
}

// 7z is very fast, so, use ultra compression
/** @internal */
export async function archive(format: string, outFile: string, dirToArchive: string, options: ArchiveOptions = {}): Promise<string> {
const args = compute7zCompressArgs(format, options)
// remove file before - 7z doesn't overwrite file, but update
let use7z = true
if (process.platform === "darwin" && format === "zip" && dirToArchive.normalize("NFC") !== dirToArchive) {
log.warn({ reason: "7z doesn't support NFD-normalized filenames" }, `using zip`)
use7z = false
}
const args = use7z ? compute7zCompressArgs(format, options) : computeZipCompressArgs(options)
// remove file before - 7z and zip doesn't overwrite file, but update
await unlinkIfExists(outFile)

args.push(outFile, options.withoutDir ? "." : path.basename(dirToArchive))
if (options.excluded != null) {
for (const mask of options.excluded) {
args.push(`-xr!${mask}`)
args.push(use7z ? `-xr!${mask}` : `-x${mask}`)
}
}

try {
await chmod(path7za, 0o755)
if (use7z) {
await chmod(path7za, 0o755)
}
await exec(
path7za,
use7z ? path7za : "zip",
args,
{
cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive),
Expand Down

0 comments on commit 0f43989

Please sign in to comment.