Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions src/asar-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Member

@erickzhao erickzhao Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an open issue for this in the repo? Or was this supposed to link to the PR?

Copy link
Copy Markdown
Author

@akkay-fp akkay-fp Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was an oversight on my end. I haven't opened a separate issue because the PR description covers the problem comprehensively. I have updated the link to point here.

const unpackDirs = new Set<string>();
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,
});
Expand Down