From f0930fc42e689c64d1e5a89424132ee76fdad4e6 Mon Sep 17 00:00:00 2001 From: akshayApplore Date: Wed, 11 Mar 2026 02:09:54 +0530 Subject: [PATCH 1/3] fix: use directory-level unpack patterns to avoid minimatch length limit When merging ASARs for universal builds, the unpack pattern was constructed by listing every individual unpacked file path in a brace expansion like `{file1,file2,...}`. For projects with many unpacked files (e.g. auto-unpacked native modules), this pattern can exceed minimatch's 64 KiB limit, causing a "pattern is too long" TypeError. This change groups unpacked files by their top-level directory (e.g. `node_modules/pkg` or `dist/main`) and uses `**` glob patterns instead. This reduces thousands of entries to a handful of directory patterns while preserving the same unpack behavior. Fixes https://github.com/electron-userland/electron-builder/issues/7044 --- src/asar-utils.ts | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/asar-utils.ts b/src/asar-utils.ts index aaeed61..19b97b6 100644 --- a/src/asar-utils.ts +++ b/src/asar-utils.ts @@ -210,15 +210,46 @@ export const mergeASARs = async ({ d(`creating archive at ${outputAsarPath}`); - const resolvedUnpack = Array.from(unpackedFiles).map((file) => path.join(x64Dir, file)); + // Build a compact unpack pattern from directory prefixes instead of + // listing every file individually. When there are many unpacked files + // (e.g. auto-unpacked native modules) the old brace-expansion approach + // can exceed minimatch's 64 KiB pattern-length limit. + // See: https://github.com/electron/universal/issues/XXX + const unpackDirs = new Set(); + for (const file of unpackedFiles) { + const parts = file.replace(/^\//, '').split('/'); + let dir: string; + if (parts[0] === 'node_modules' && parts.length > 1) { + // Handle scoped packages (e.g. @img/sharp-darwin-arm64) + dir = + parts[1].startsWith('@') && parts.length > 2 + ? parts.slice(0, 3).join('/') + : parts.slice(0, 2).join('/'); + } else if (parts.length > 1) { + dir = parts.slice(0, 2).join('/'); + } else { + dir = parts[0]; + } + unpackDirs.add(dir); + } + + const dirPatterns = Array.from(unpackDirs).map((dir) => + path.join(x64Dir, dir, '**'), + ); let unpack: string | undefined; - if (resolvedUnpack.length > 1) { - unpack = `{${resolvedUnpack.join(',')}}`; - } else if (resolvedUnpack.length === 1) { - unpack = resolvedUnpack[0]; + if (dirPatterns.length > 1) { + unpack = `{${dirPatterns.join(',')}}`; + } else if (dirPatterns.length === 1) { + unpack = dirPatterns[0]; } + d( + `unpack pattern (${unpackedFiles.size} files, ${unpackDirs.size} dirs): ${ + unpack ? unpack.substring(0, 200) + '...' : 'none' + }`, + ); + await asar.createPackageWithOptions(x64Dir, outputAsarPath, { unpack, }); From 3d878186ae7a66bc245bf954516204d667db4e64 Mon Sep 17 00:00:00 2001 From: akkay-fp Date: Wed, 11 Mar 2026 17:35:30 +0530 Subject: [PATCH 2/3] fix: update source code comment to reference PR #178 --- src/asar-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asar-utils.ts b/src/asar-utils.ts index 19b97b6..6a5ec41 100644 --- a/src/asar-utils.ts +++ b/src/asar-utils.ts @@ -214,7 +214,7 @@ export const mergeASARs = async ({ // listing every file individually. When there are many unpacked files // (e.g. auto-unpacked native modules) the old brace-expansion approach // can exceed minimatch's 64 KiB pattern-length limit. - // See: https://github.com/electron/universal/issues/XXX + // See: https://github.com/electron/universal/pull/178 const unpackDirs = new Set(); for (const file of unpackedFiles) { const parts = file.replace(/^\//, '').split('/'); From 458988559a24830a0bc07038769bda27547e94f7 Mon Sep 17 00:00:00 2001 From: akshayApplore Date: Thu, 12 Mar 2026 09:52:12 +0530 Subject: [PATCH 3/3] style: fix prettier formatting --- src/asar-utils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/asar-utils.ts b/src/asar-utils.ts index 6a5ec41..f006d1c 100644 --- a/src/asar-utils.ts +++ b/src/asar-utils.ts @@ -233,9 +233,7 @@ export const mergeASARs = async ({ unpackDirs.add(dir); } - const dirPatterns = Array.from(unpackDirs).map((dir) => - path.join(x64Dir, dir, '**'), - ); + const dirPatterns = Array.from(unpackDirs).map((dir) => path.join(x64Dir, dir, '**')); let unpack: string | undefined; if (dirPatterns.length > 1) {