From ce0b33a888a3db154107dc77c5a29b7f00a034d1 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Fri, 6 Sep 2024 19:32:30 +0900 Subject: [PATCH] fix: duplicate vsda --- build/gulpfile.vscode.js | 2 ++ build/lib/asar.js | 21 ++++++++++++++++++++- build/lib/asar.ts | 22 +++++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index a216e9e99fb..cf55e6a1696 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -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( diff --git a/build/lib/asar.js b/build/lib/asar.js index 4e7c1651d74..0660fe9fa68 100644 --- a/build/lib/asar.js +++ b/build/lib/asar.js @@ -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) { diff --git a/build/lib/asar.ts b/build/lib/asar.ts index de0278fc20c..a1897df42ac 100644 --- a/build/lib/asar.ts +++ b/build/lib/asar.ts @@ -17,7 +17,7 @@ declare class AsarFilesystem { insertFile(path: string, shouldUnpack: boolean, file: { stat: { size: number; mode: number } }, options: {}): Promise; } -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);