diff --git a/src/asar-utils.ts b/src/asar-utils.ts index aaeed61..f006d1c 100644 --- a/src/asar-utils.ts +++ b/src/asar-utils.ts @@ -210,15 +210,44 @@ 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/pull/178 + 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, });