Skip to content

Commit 08773af

Browse files
authored
feat: Expanding ${arch} macro for mac.binaries in case of unpacked files within universal builds (#9263)
1 parent 716cb71 commit 08773af

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

.changeset/flat-pets-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
feat: Expanding `${arch}` macro properly for `mac.binaries` in case of native node packages for unpacked files for macos `universal` target

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { createCommonTarget, NoOpTarget } from "./targets/targetFactory"
2121
import { isMacOsHighSierra } from "./util/macosVersion"
2222
import { getTemplatePath } from "./util/pathManager"
2323
import { resolveFunction } from "./util/resolve"
24+
import { expandMacro as doExpandMacro } from "./util/macroExpander"
2425

2526
export type CustomMacSignOptions = SignOptions
2627
export type CustomMacSign = (configuration: CustomMacSignOptions, packager: MacPackager) => Promise<void>
@@ -69,6 +70,15 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
6970
return this.info.framework.macOsDefaultTargets
7071
}
7172

73+
expandArch(pattern: string, arch?: Arch | null): string[] {
74+
if (arch === Arch.universal) {
75+
// Universal build has `app-x64.asar.unpacked` & `app-arm64.asar.unpacked`
76+
return [doExpandMacro(pattern, Arch[Arch.arm64], this.appInfo, {}, false), doExpandMacro(pattern, Arch[Arch.x64], this.appInfo, {}, false)]
77+
}
78+
// Every other build keeps the name as `app.asar.unpacked`
79+
return [doExpandMacro(pattern, null, this.appInfo, {}, false)]
80+
}
81+
7282
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7383
protected prepareAppInfo(appInfo: AppInfo): AppInfo {
7484
// codesign requires the filename to be normalized to the NFD form
@@ -303,15 +313,22 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
303313
let binaries = options.binaries || undefined
304314
if (binaries) {
305315
// Accept absolute paths for external binaries, else resolve relative paths from the artifact's app Contents path.
306-
binaries = await Promise.all(
307-
binaries.map(async destination => {
308-
if (await statOrNull(destination)) {
309-
return destination
310-
}
311-
return path.resolve(appPath, destination)
312-
})
313-
)
314-
log.info({ binaries }, "signing additional user-defined binaries")
316+
binaries = (
317+
await Promise.all(
318+
binaries.flatMap(async destination => {
319+
const expandedDestination = this.expandArch(destination, arch)
320+
return await Promise.all(
321+
expandedDestination.map(async d => {
322+
if (await statOrNull(d)) {
323+
return d
324+
}
325+
return path.resolve(appPath, d)
326+
})
327+
)
328+
})
329+
)
330+
).flat()
331+
log.info({ binaries, arch: arch == null ? null : Arch[arch] }, "signing additional user-defined binaries for arch")
315332
}
316333
const customSignOptions: MasConfiguration | MacConfiguration = (isMas ? masOptions : this.platformSpecificBuildOptions) || this.platformSpecificBuildOptions
317334

0 commit comments

Comments
 (0)