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

@@ -382,6 +382,8 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op
] : [
'**/*.mk',
'!node_modules/vsda/**' // stay compatible with extensions that depend on us shipping `vsda` into ASAR
], isAMD() ? [] : [
'node_modules/vsda/**' // retain copy of `vsda` in node_modules for internal use
], 'node_modules.asar'));
let all = es.merge(

View File

@@ -11,7 +11,7 @@ const pickle = require('chromium-pickle-js');
const Filesystem = require('asar/lib/filesystem');
const VinylFile = require("vinyl");
const minimatch = require("minimatch");
function createAsar(folderPath, unpackGlobs, skipGlobs, destFilename) {
function createAsar(folderPath, unpackGlobs, skipGlobs, duplicateGlobs, destFilename) {
const shouldUnpackFile = (file) => {
for (let i = 0; i < unpackGlobs.length; i++) {
if (minimatch(file.relative, unpackGlobs[i])) {
@@ -28,6 +28,16 @@ function createAsar(folderPath, unpackGlobs, skipGlobs, destFilename) {
}
return false;
};
// Files that should be duplicated between
// node_modules.asar and node_modules
const shouldDuplicateFile = (file) => {
for (const duplicateGlob of duplicateGlobs) {
if (minimatch(file.relative, duplicateGlob)) {
return true;
}
}
return false;
};
const filesystem = new Filesystem(folderPath);
const out = [];
// Keep track of pending inserts
@@ -81,6 +91,15 @@ function createAsar(folderPath, unpackGlobs, skipGlobs, destFilename) {
}));
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);
if (shouldUnpack) {

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);