From f83f05f6f24a36b96d0e0c7786e1a12e5c762389 Mon Sep 17 00:00:00 2001 From: jebibot <83044352+jebibot@users.noreply.github.com> Date: Tue, 28 Nov 2023 03:53:05 +0900 Subject: [PATCH] fix(mac): normalize filename to NFD form (#7901) --- .changeset/thick-flowers-bathe.md | 5 +++++ packages/app-builder-lib/src/appInfo.ts | 11 ++++++++--- packages/app-builder-lib/src/macPackager.ts | 3 ++- packages/app-builder-lib/src/util/filename.ts | 5 +++-- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 .changeset/thick-flowers-bathe.md diff --git a/.changeset/thick-flowers-bathe.md b/.changeset/thick-flowers-bathe.md new file mode 100644 index 00000000000..c24ebf51dbe --- /dev/null +++ b/.changeset/thick-flowers-bathe.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +fix codesign and DMG layout when productName or executableName contains Unicode diff --git a/packages/app-builder-lib/src/appInfo.ts b/packages/app-builder-lib/src/appInfo.ts index 6c48c373ab3..33e8b134809 100644 --- a/packages/app-builder-lib/src/appInfo.ts +++ b/packages/app-builder-lib/src/appInfo.ts @@ -32,7 +32,12 @@ export class AppInfo { readonly sanitizedProductName: string readonly productFilename: string - constructor(private readonly info: Packager, buildVersion: string | null | undefined, private readonly platformSpecificOptions: PlatformSpecificBuildOptions | null = null) { + constructor( + private readonly info: Packager, + buildVersion: string | null | undefined, + private readonly platformSpecificOptions: PlatformSpecificBuildOptions | null = null, + normalizeNfd = false + ) { this.version = info.metadata.version! if (buildVersion == null) { @@ -63,10 +68,10 @@ export class AppInfo { } this.productName = info.config.productName || info.metadata.productName || info.metadata.name! - this.sanitizedProductName = sanitizeFileName(this.productName) + this.sanitizedProductName = sanitizeFileName(this.productName, normalizeNfd) const executableName = platformSpecificOptions?.executableName ?? info.config.executableName - this.productFilename = executableName != null ? sanitizeFileName(executableName) : this.sanitizedProductName + this.productFilename = executableName != null ? sanitizeFileName(executableName, normalizeNfd) : this.sanitizedProductName } get channel(): string | null { diff --git a/packages/app-builder-lib/src/macPackager.ts b/packages/app-builder-lib/src/macPackager.ts index c2779059452..d105ad3006f 100644 --- a/packages/app-builder-lib/src/macPackager.ts +++ b/packages/app-builder-lib/src/macPackager.ts @@ -58,7 +58,8 @@ export default class MacPackager extends PlatformPackager { // eslint-disable-next-line @typescript-eslint/no-unused-vars protected prepareAppInfo(appInfo: AppInfo): AppInfo { - return new AppInfo(this.info, this.platformSpecificBuildOptions.bundleVersion, this.platformSpecificBuildOptions) + // codesign requires the filename to be normalized to the NFD form + return new AppInfo(this.info, this.platformSpecificBuildOptions.bundleVersion, this.platformSpecificBuildOptions, true) } async getIconPath(): Promise { diff --git a/packages/app-builder-lib/src/util/filename.ts b/packages/app-builder-lib/src/util/filename.ts index 58cf72ee83f..7ef8ef4b2da 100644 --- a/packages/app-builder-lib/src/util/filename.ts +++ b/packages/app-builder-lib/src/util/filename.ts @@ -2,8 +2,9 @@ import * as _sanitizeFileName from "sanitize-filename" import * as path from "path" -export function sanitizeFileName(s: string): string { - return _sanitizeFileName(s) +export function sanitizeFileName(s: string, normalizeNfd = false): string { + const sanitized = _sanitizeFileName(s) + return normalizeNfd ? sanitized.normalize("NFD") : sanitized } // Get the filetype from a filename. Returns a string of one or more file extensions,