fix: duplicate vsda

This commit is contained in:
deepak1556
2024-09-06 19:32:30 +09:00
parent 7ba544f617
commit ce0b33a888
3 changed files with 43 additions and 2 deletions

View File

@@ -17,7 +17,7 @@ declare class AsarFilesystem {
insertFile(path: string, shouldUnpack: boolean, file: { stat: { size: number; mode: number } }, options: {}): Promise<void>;
}
export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs: string[], destFilename: string): NodeJS.ReadWriteStream {
export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs: string[], duplicateGlobs: string[], destFilename: string): NodeJS.ReadWriteStream {
const shouldUnpackFile = (file: VinylFile): boolean => {
for (let i = 0; i < unpackGlobs.length; i++) {
@@ -37,6 +37,17 @@ export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs:
return false;
};
// Files that should be duplicated between
// node_modules.asar and node_modules
const shouldDuplicateFile = (file: VinylFile): boolean => {
for (const duplicateGlob of duplicateGlobs) {
if (minimatch(file.relative, duplicateGlob)) {
return true;
}
}
return false;
};
const filesystem = new Filesystem(folderPath);
const out: Buffer[] = [];
@@ -96,6 +107,15 @@ export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs:
}));
return;
}
if (shouldDuplicateFile(file)) {
console.log(file.relative);
this.queue(new VinylFile({
base: '.',
path: file.path,
stat: file.stat,
contents: file.contents
}));
}
const shouldUnpack = shouldUnpackFile(file);
insertFile(file.relative, { size: file.contents.length, mode: file.stat.mode }, shouldUnpack);