update electron to v43
This commit is contained in:
parent
68ac0beedf
commit
fb6c8b6ee9
5385 changed files with 513060 additions and 123058 deletions
11
electron/node_modules/app-builder-lib/out/asar/asar.d.ts
generated
vendored
11
electron/node_modules/app-builder-lib/out/asar/asar.d.ts
generated
vendored
|
|
@ -1,4 +1,3 @@
|
|||
/// <reference types="node" />
|
||||
import { Stats } from "fs-extra";
|
||||
export interface ReadAsarHeader {
|
||||
readonly header: string;
|
||||
|
|
@ -10,6 +9,15 @@ export interface NodeIntegrity {
|
|||
blockSize: number;
|
||||
blocks: Array<string>;
|
||||
}
|
||||
export declare class Node {
|
||||
files?: Record<string, Node>;
|
||||
unpacked?: boolean;
|
||||
size?: number;
|
||||
offset?: string;
|
||||
executable?: boolean;
|
||||
link?: string;
|
||||
integrity?: NodeIntegrity;
|
||||
}
|
||||
export declare class AsarFilesystem {
|
||||
readonly src: string;
|
||||
readonly header: Node;
|
||||
|
|
@ -23,6 +31,7 @@ export declare class AsarFilesystem {
|
|||
getFile(p: string, followLinks?: boolean): Node;
|
||||
readJson(file: string): Promise<any>;
|
||||
readFile(file: string): Promise<Buffer>;
|
||||
private newNode;
|
||||
}
|
||||
export declare function readAsarHeader(archive: string): Promise<ReadAsarHeader>;
|
||||
export declare function readAsar(archive: string): Promise<AsarFilesystem>;
|
||||
|
|
|
|||
49
electron/node_modules/app-builder-lib/out/asar/asar.js
generated
vendored
49
electron/node_modules/app-builder-lib/out/asar/asar.js
generated
vendored
|
|
@ -1,10 +1,12 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.readAsarJson = exports.readAsar = exports.readAsarHeader = exports.AsarFilesystem = exports.Node = void 0;
|
||||
exports.AsarFilesystem = exports.Node = void 0;
|
||||
exports.readAsarHeader = readAsarHeader;
|
||||
exports.readAsar = readAsar;
|
||||
exports.readAsarJson = readAsarJson;
|
||||
const chromium_pickle_js_1 = require("chromium-pickle-js");
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const path = require("path");
|
||||
/** @internal */
|
||||
class Node {
|
||||
}
|
||||
exports.Node = Node;
|
||||
|
|
@ -15,20 +17,23 @@ class AsarFilesystem {
|
|||
this.headerSize = headerSize;
|
||||
this.offset = 0;
|
||||
if (this.header.files == null) {
|
||||
this.header.files = {};
|
||||
this.header.files = this.newNode();
|
||||
}
|
||||
}
|
||||
searchNodeFromDirectory(p, isCreate) {
|
||||
let node = this.header;
|
||||
for (const dir of p.split(path.sep)) {
|
||||
if (dir !== ".") {
|
||||
if (node == null) {
|
||||
throw new Error(`Cannot find node for path: ${p} (node is null at ${dir})`);
|
||||
}
|
||||
let child = node.files[dir];
|
||||
if (child == null) {
|
||||
if (!isCreate) {
|
||||
return null;
|
||||
}
|
||||
child = new Node();
|
||||
child.files = {};
|
||||
child.files = this.newNode();
|
||||
node.files[dir] = child;
|
||||
}
|
||||
node = child;
|
||||
|
|
@ -42,8 +47,11 @@ class AsarFilesystem {
|
|||
}
|
||||
const name = path.basename(p);
|
||||
const dirNode = this.searchNodeFromDirectory(path.dirname(p), true);
|
||||
if (dirNode == null) {
|
||||
throw new Error(`Cannot find node for path: ${p} (node is null at ${path.dirname(p)})`);
|
||||
}
|
||||
if (dirNode.files == null) {
|
||||
dirNode.files = {};
|
||||
dirNode.files = this.newNode();
|
||||
}
|
||||
let result = dirNode.files[name];
|
||||
if (result == null) {
|
||||
|
|
@ -74,7 +82,7 @@ class AsarFilesystem {
|
|||
}
|
||||
let children = dirNode.files;
|
||||
if (children == null) {
|
||||
children = {};
|
||||
children = this.newNode();
|
||||
dirNode.files = children;
|
||||
}
|
||||
children[path.basename(file)] = node;
|
||||
|
|
@ -82,6 +90,9 @@ class AsarFilesystem {
|
|||
}
|
||||
getNode(p) {
|
||||
const node = this.searchNodeFromDirectory(path.dirname(p), false);
|
||||
if (node == null) {
|
||||
throw new Error(`Cannot find node for path: ${p} (node is null at ${path.dirname(p)})`);
|
||||
}
|
||||
return node.files[path.basename(p)];
|
||||
}
|
||||
getFile(p, followLinks = true) {
|
||||
|
|
@ -95,41 +106,41 @@ class AsarFilesystem {
|
|||
readFile(file) {
|
||||
return readFileFromAsar(this, file, this.getFile(file));
|
||||
}
|
||||
newNode() {
|
||||
return Object.create(null);
|
||||
}
|
||||
}
|
||||
exports.AsarFilesystem = AsarFilesystem;
|
||||
async function readAsarHeader(archive) {
|
||||
const fd = await fs_extra_1.open(archive, "r");
|
||||
const fd = await (0, fs_extra_1.open)(archive, "r");
|
||||
let size;
|
||||
let headerBuf;
|
||||
try {
|
||||
const sizeBuf = Buffer.allocUnsafe(8);
|
||||
if ((await fs_extra_1.read(fd, sizeBuf, 0, 8, null)).bytesRead !== 8) {
|
||||
if ((await (0, fs_extra_1.read)(fd, sizeBuf, 0, 8, null)).bytesRead !== 8) {
|
||||
throw new Error("Unable to read header size");
|
||||
}
|
||||
const sizePickle = chromium_pickle_js_1.createFromBuffer(sizeBuf);
|
||||
const sizePickle = (0, chromium_pickle_js_1.createFromBuffer)(sizeBuf);
|
||||
size = sizePickle.createIterator().readUInt32();
|
||||
headerBuf = Buffer.allocUnsafe(size);
|
||||
if ((await fs_extra_1.read(fd, headerBuf, 0, size, null)).bytesRead !== size) {
|
||||
if ((await (0, fs_extra_1.read)(fd, headerBuf, 0, size, null)).bytesRead !== size) {
|
||||
throw new Error("Unable to read header");
|
||||
}
|
||||
}
|
||||
finally {
|
||||
await fs_extra_1.close(fd);
|
||||
await (0, fs_extra_1.close)(fd);
|
||||
}
|
||||
const headerPickle = chromium_pickle_js_1.createFromBuffer(headerBuf);
|
||||
const headerPickle = (0, chromium_pickle_js_1.createFromBuffer)(headerBuf);
|
||||
return { header: headerPickle.createIterator().readString(), size };
|
||||
}
|
||||
exports.readAsarHeader = readAsarHeader;
|
||||
async function readAsar(archive) {
|
||||
const { header, size } = await readAsarHeader(archive);
|
||||
return new AsarFilesystem(archive, JSON.parse(header), size);
|
||||
}
|
||||
exports.readAsar = readAsar;
|
||||
async function readAsarJson(archive, file) {
|
||||
const fs = await readAsar(archive);
|
||||
return await fs.readJson(file);
|
||||
}
|
||||
exports.readAsarJson = readAsarJson;
|
||||
async function readFileFromAsar(filesystem, filename, info) {
|
||||
const size = info.size;
|
||||
const buffer = Buffer.allocUnsafe(size);
|
||||
|
|
@ -137,15 +148,15 @@ async function readFileFromAsar(filesystem, filename, info) {
|
|||
return buffer;
|
||||
}
|
||||
if (info.unpacked) {
|
||||
return await fs_extra_1.readFile(path.join(`${filesystem.src}.unpacked`, filename));
|
||||
return await (0, fs_extra_1.readFile)(path.join(`${filesystem.src}.unpacked`, filename));
|
||||
}
|
||||
const fd = await fs_extra_1.open(filesystem.src, "r");
|
||||
const fd = await (0, fs_extra_1.open)(filesystem.src, "r");
|
||||
try {
|
||||
const offset = 8 + filesystem.headerSize + parseInt(info.offset, 10);
|
||||
await fs_extra_1.read(fd, buffer, 0, size, offset);
|
||||
await (0, fs_extra_1.read)(fd, buffer, 0, size, offset);
|
||||
}
|
||||
finally {
|
||||
await fs_extra_1.close(fd);
|
||||
await (0, fs_extra_1.close)(fd);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
|||
2
electron/node_modules/app-builder-lib/out/asar/asar.js.map
generated
vendored
2
electron/node_modules/app-builder-lib/out/asar/asar.js.map
generated
vendored
File diff suppressed because one or more lines are too long
3
electron/node_modules/app-builder-lib/out/asar/asarFileChecker.d.ts
generated
vendored
3
electron/node_modules/app-builder-lib/out/asar/asarFileChecker.d.ts
generated
vendored
|
|
@ -1 +1,2 @@
|
|||
export {};
|
||||
import type { FilesystemEntry } from "@electron/asar/lib/filesystem";
|
||||
export declare function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string): Promise<FilesystemEntry>;
|
||||
|
|
|
|||
29
electron/node_modules/app-builder-lib/out/asar/asarFileChecker.js
generated
vendored
29
electron/node_modules/app-builder-lib/out/asar/asarFileChecker.js
generated
vendored
|
|
@ -1,38 +1,25 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.checkFileInArchive = void 0;
|
||||
const fs_1 = require("builder-util/out/fs");
|
||||
const asar_1 = require("./asar");
|
||||
/** @internal */
|
||||
exports.checkFileInArchive = checkFileInArchive;
|
||||
const dynamicImport_1 = require("../util/dynamicImport");
|
||||
async function checkFileInArchive(asarFile, relativeFile, messagePrefix) {
|
||||
const asar = await (0, dynamicImport_1.dynamicImport)("@electron/asar");
|
||||
function error(text) {
|
||||
return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`);
|
||||
}
|
||||
let fs;
|
||||
try {
|
||||
fs = await asar_1.readAsar(asarFile);
|
||||
}
|
||||
catch (e) {
|
||||
throw error(`is corrupted: ${e}`);
|
||||
}
|
||||
let stat;
|
||||
try {
|
||||
stat = fs.getFile(relativeFile);
|
||||
stat = asar.statFile(asarFile, relativeFile, false);
|
||||
}
|
||||
catch (e) {
|
||||
const fileStat = await fs_1.statOrNull(asarFile);
|
||||
if (fileStat == null) {
|
||||
throw error(`does not exist. Seems like a wrong configuration.`);
|
||||
if (e.message.includes("Cannot read properties of undefined (reading 'link')")) {
|
||||
throw error("does not exist. Seems like a wrong configuration.");
|
||||
}
|
||||
// asar throws error on access to undefined object (info.link)
|
||||
stat = null;
|
||||
}
|
||||
if (stat == null) {
|
||||
throw error(`does not exist. Seems like a wrong configuration.`);
|
||||
throw error(`is corrupted: ${e}`);
|
||||
}
|
||||
if (stat.size === 0) {
|
||||
throw error(`is corrupted: size 0`);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
exports.checkFileInArchive = checkFileInArchive;
|
||||
//# sourceMappingURL=asarFileChecker.js.map
|
||||
2
electron/node_modules/app-builder-lib/out/asar/asarFileChecker.js.map
generated
vendored
2
electron/node_modules/app-builder-lib/out/asar/asarFileChecker.js.map
generated
vendored
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"asarFileChecker.js","sourceRoot":"","sources":["../../src/asar/asarFileChecker.ts"],"names":[],"mappings":";;;AAAA,4CAAgD;AAChD,iCAAuC;AAEvC,gBAAgB;AACT,KAAK,UAAU,kBAAkB,CAAC,QAAgB,EAAE,YAAoB,EAAE,aAAqB;IACpG,SAAS,KAAK,CAAC,IAAY;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,aAAa,KAAK,YAAY,aAAa,QAAQ,KAAK,IAAI,EAAE,CAAC,CAAA;IACrF,CAAC;IAED,IAAI,EAAE,CAAA;IACN,IAAI;QACF,EAAE,GAAG,MAAM,eAAQ,CAAC,QAAQ,CAAC,CAAA;KAC9B;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA;KAClC;IAED,IAAI,IAAiB,CAAA;IACrB,IAAI;QACF,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,QAAQ,GAAG,MAAM,eAAU,CAAC,QAAQ,CAAC,CAAA;QAC3C,IAAI,QAAQ,IAAI,IAAI,EAAE;YACpB,MAAM,KAAK,CAAC,mDAAmD,CAAC,CAAA;SACjE;QAED,8DAA8D;QAC9D,IAAI,GAAG,IAAI,CAAA;KACZ;IAED,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,MAAM,KAAK,CAAC,mDAAmD,CAAC,CAAA;KACjE;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE;QACnB,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAA;KACpC;AACH,CAAC;AA/BD,gDA+BC","sourcesContent":["import { statOrNull } from \"builder-util/out/fs\"\nimport { Node, readAsar } from \"./asar\"\n\n/** @internal */\nexport async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {\n function error(text: string) {\n return new Error(`${messagePrefix} \"${relativeFile}\" in the \"${asarFile}\" ${text}`)\n }\n\n let fs\n try {\n fs = await readAsar(asarFile)\n } catch (e) {\n throw error(`is corrupted: ${e}`)\n }\n\n let stat: Node | null\n try {\n stat = fs.getFile(relativeFile)\n } catch (e) {\n const fileStat = await statOrNull(asarFile)\n if (fileStat == null) {\n throw error(`does not exist. Seems like a wrong configuration.`)\n }\n\n // asar throws error on access to undefined object (info.link)\n stat = null\n }\n\n if (stat == null) {\n throw error(`does not exist. Seems like a wrong configuration.`)\n }\n if (stat.size === 0) {\n throw error(`is corrupted: size 0`)\n }\n}\n"]}
|
||||
{"version":3,"file":"asarFileChecker.js","sourceRoot":"","sources":["../../src/asar/asarFileChecker.ts"],"names":[],"mappings":";;AAGA,gDAkBC;AApBD,yDAAqD;AAE9C,KAAK,UAAU,kBAAkB,CAAC,QAAgB,EAAE,YAAoB,EAAE,aAAqB;IACpG,MAAM,IAAI,GAAG,MAAM,IAAA,6BAAa,EAAkC,gBAAgB,CAAC,CAAA;IACnF,SAAS,KAAK,CAAC,IAAY;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,aAAa,KAAK,YAAY,aAAa,QAAQ,KAAK,IAAI,EAAE,CAAC,CAAA;IACrF,CAAC;IACD,IAAI,IAAqB,CAAA;IACzB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;IACrD,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,sDAAsD,CAAC,EAAE,CAAC;YAC/E,MAAM,KAAK,CAAC,mDAAmD,CAAC,CAAA;QAClE,CAAC;QACD,MAAM,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA;IACnC,CAAC;IACD,IAAK,IAA4B,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QAC7C,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import type { FilesystemEntry, FilesystemFileEntry } from \"@electron/asar/lib/filesystem\"\nimport { dynamicImport } from \"../util/dynamicImport\"\n\nexport async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string): Promise<FilesystemEntry> {\n const asar = await dynamicImport<typeof import(\"@electron/asar\")>(\"@electron/asar\")\n function error(text: string) {\n return new Error(`${messagePrefix} \"${relativeFile}\" in the \"${asarFile}\" ${text}`)\n }\n let stat: FilesystemEntry\n try {\n stat = asar.statFile(asarFile, relativeFile, false)\n } catch (e: any) {\n if (e.message.includes(\"Cannot read properties of undefined (reading 'link')\")) {\n throw error(\"does not exist. Seems like a wrong configuration.\")\n }\n throw error(`is corrupted: ${e}`)\n }\n if ((stat as FilesystemFileEntry).size === 0) {\n throw error(`is corrupted: size 0`)\n }\n return stat\n}\n"]}
|
||||
480
electron/node_modules/app-builder-lib/out/asar/asarUtil.js
generated
vendored
480
electron/node_modules/app-builder-lib/out/asar/asarUtil.js
generated
vendored
|
|
@ -2,240 +2,284 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AsarPackager = void 0;
|
||||
const builder_util_1 = require("builder-util");
|
||||
const dynamicImport_1 = require("../util/dynamicImport");
|
||||
const fs_1 = require("builder-util/out/fs");
|
||||
const fs_2 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const fs = require("fs-extra");
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const path = require("path");
|
||||
const appFileCopier_1 = require("../util/appFileCopier");
|
||||
const asar_1 = require("./asar");
|
||||
const integrity_1 = require("./integrity");
|
||||
const unpackDetector_1 = require("./unpackDetector");
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const pickle = require("chromium-pickle-js");
|
||||
const stream_1 = require("stream");
|
||||
const os = require("os");
|
||||
const resolvePath = async (file) => (file && (await (0, fs_1.exists)(file)) ? fs.realpath(file).catch(() => path.resolve(file)) : undefined);
|
||||
const resolvePaths = async (filepaths) => {
|
||||
return Promise.all(filepaths.map(resolvePath)).then(paths => paths.filter((it) => it != null));
|
||||
};
|
||||
const DENYLIST = resolvePaths([
|
||||
"/usr",
|
||||
"/lib",
|
||||
"/bin",
|
||||
"/sbin",
|
||||
"/etc",
|
||||
"/tmp",
|
||||
"/var", // block whole /var by default. If $HOME is under /var, it's explicitly in ALLOWLIST - https://github.com/electron-userland/electron-builder/issues/9025#issuecomment-3575380041
|
||||
// macOS system directories
|
||||
"/System",
|
||||
"/Library",
|
||||
"/private",
|
||||
// Windows system directories
|
||||
process.env.SystemRoot,
|
||||
process.env.WINDIR,
|
||||
]);
|
||||
const ALLOWLIST = resolvePaths([
|
||||
os.tmpdir(), // always allow temp dir
|
||||
os.homedir(), // always allow home dir
|
||||
]);
|
||||
/** @internal */
|
||||
class AsarPackager {
|
||||
constructor(src, destination, options, unpackPattern) {
|
||||
this.src = src;
|
||||
this.destination = destination;
|
||||
this.options = options;
|
||||
this.unpackPattern = unpackPattern;
|
||||
this.fs = new asar_1.AsarFilesystem(this.src);
|
||||
this.outFile = path.join(destination, "app.asar");
|
||||
this.unpackedDest = `${this.outFile}.unpacked`;
|
||||
constructor(packager, config) {
|
||||
this.packager = packager;
|
||||
this.config = config;
|
||||
this.outFile = path.join(config.resourcePath, `app.asar`);
|
||||
}
|
||||
// sort files to minimize file change (i.e. asar file is not changed dramatically on small change)
|
||||
async pack(fileSets, packager) {
|
||||
if (this.options.ordering != null) {
|
||||
// ordering doesn't support transformed files, but ordering is not used functionality - wait user report to fix it
|
||||
await order(fileSets[0].files, this.options.ordering, fileSets[0].src);
|
||||
}
|
||||
await promises_1.mkdir(path.dirname(this.outFile), { recursive: true });
|
||||
const unpackedFileIndexMap = new Map();
|
||||
for (const fileSet of fileSets) {
|
||||
unpackedFileIndexMap.set(fileSet, await this.createPackageFromFiles(fileSet, packager.info));
|
||||
}
|
||||
await this.writeAsarFile(fileSets, unpackedFileIndexMap);
|
||||
async pack(fileSets) {
|
||||
const orderedFileSets = [
|
||||
// Write dependencies first to minimize offset changes to asar header
|
||||
...fileSets.slice(1),
|
||||
// Finish with the app files that change most often
|
||||
fileSets[0],
|
||||
].map(set => this.orderFileSet(set));
|
||||
const streams = await this.processFileSets(orderedFileSets);
|
||||
await this.executeElectronAsar(streams);
|
||||
}
|
||||
async createPackageFromFiles(fileSet, packager) {
|
||||
const metadata = fileSet.metadata;
|
||||
// search auto unpacked dir
|
||||
const unpackedDirs = new Set();
|
||||
const rootForAppFilesWithoutAsar = path.join(this.destination, "app");
|
||||
if (this.options.smartUnpack !== false) {
|
||||
await unpackDetector_1.detectUnpackedDirs(fileSet, unpackedDirs, this.unpackedDest, rootForAppFilesWithoutAsar);
|
||||
}
|
||||
const dirToCreateForUnpackedFiles = new Set(unpackedDirs);
|
||||
const correctDirNodeUnpackedFlag = async (filePathInArchive, dirNode) => {
|
||||
for (const dir of unpackedDirs) {
|
||||
if (filePathInArchive.length > dir.length + 2 && filePathInArchive[dir.length] === path.sep && filePathInArchive.startsWith(dir)) {
|
||||
dirNode.unpacked = true;
|
||||
unpackedDirs.add(filePathInArchive);
|
||||
// not all dirs marked as unpacked after first iteration - because node module dir can be marked as unpacked after processing node module dir content
|
||||
// e.g. node-notifier/example/advanced.js processed, but only on process vendor/terminal-notifier.app module will be marked as unpacked
|
||||
await promises_1.mkdir(path.join(this.unpackedDest, filePathInArchive), { recursive: true });
|
||||
break;
|
||||
}
|
||||
async executeElectronAsar(streams) {
|
||||
// override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)
|
||||
const consoleLogger = console.log;
|
||||
console.log = (...args) => {
|
||||
if (args[0] === "Ordering file has 100% coverage.") {
|
||||
return; // no need to log, this means our ordering logic is working correctly
|
||||
}
|
||||
builder_util_1.log.info({ args }, "logging @electron/asar");
|
||||
};
|
||||
const transformedFiles = fileSet.transformedFiles;
|
||||
const taskManager = new builder_util_1.AsyncTaskManager(packager.cancellationToken);
|
||||
const fileCopier = new fs_1.FileCopier();
|
||||
let currentDirNode = null;
|
||||
let currentDirPath = null;
|
||||
const unpackedFileIndexSet = new Set();
|
||||
for (let i = 0, n = fileSet.files.length; i < n; i++) {
|
||||
const file = fileSet.files[i];
|
||||
const stat = metadata.get(file);
|
||||
if (stat == null) {
|
||||
continue;
|
||||
}
|
||||
const pathInArchive = path.relative(rootForAppFilesWithoutAsar, appFileCopier_1.getDestinationPath(file, fileSet));
|
||||
if (stat.isSymbolicLink()) {
|
||||
const s = stat;
|
||||
this.fs.getOrCreateNode(pathInArchive).link = s.relativeLink;
|
||||
s.pathInArchive = pathInArchive;
|
||||
unpackedFileIndexSet.add(i);
|
||||
continue;
|
||||
}
|
||||
let fileParent = path.dirname(pathInArchive);
|
||||
if (fileParent === ".") {
|
||||
fileParent = "";
|
||||
}
|
||||
if (currentDirPath !== fileParent) {
|
||||
if (fileParent.startsWith("..")) {
|
||||
throw new Error(`Internal error: path must not start with "..": ${fileParent}`);
|
||||
}
|
||||
currentDirPath = fileParent;
|
||||
currentDirNode = this.fs.getOrCreateNode(fileParent);
|
||||
// do not check for root
|
||||
if (fileParent !== "" && !currentDirNode.unpacked) {
|
||||
if (unpackedDirs.has(fileParent)) {
|
||||
currentDirNode.unpacked = true;
|
||||
}
|
||||
else {
|
||||
await correctDirNodeUnpackedFlag(fileParent, currentDirNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
const dirNode = currentDirNode;
|
||||
const newData = transformedFiles == null ? undefined : transformedFiles.get(i);
|
||||
const isUnpacked = dirNode.unpacked || (this.unpackPattern != null && this.unpackPattern(file, stat));
|
||||
const integrity = newData === undefined ? await integrity_1.hashFile(file) : integrity_1.hashFileContents(newData);
|
||||
this.fs.addFileNode(file, dirNode, newData == undefined ? stat.size : Buffer.byteLength(newData), isUnpacked, stat, integrity);
|
||||
if (isUnpacked) {
|
||||
if (!dirNode.unpacked && !dirToCreateForUnpackedFiles.has(fileParent)) {
|
||||
dirToCreateForUnpackedFiles.add(fileParent);
|
||||
await promises_1.mkdir(path.join(this.unpackedDest, fileParent), { recursive: true });
|
||||
}
|
||||
const unpackedFile = path.join(this.unpackedDest, pathInArchive);
|
||||
taskManager.addTask(copyFileOrData(fileCopier, newData, file, unpackedFile, stat));
|
||||
if (taskManager.tasks.length > fs_1.MAX_FILE_REQUESTS) {
|
||||
await taskManager.awaitTasks();
|
||||
}
|
||||
unpackedFileIndexSet.add(i);
|
||||
}
|
||||
}
|
||||
if (taskManager.tasks.length > 0) {
|
||||
await taskManager.awaitTasks();
|
||||
}
|
||||
return unpackedFileIndexSet;
|
||||
const { createPackageFromStreams } = await (0, dynamicImport_1.dynamicImport)("@electron/asar");
|
||||
await createPackageFromStreams(this.outFile, streams);
|
||||
console.log = consoleLogger;
|
||||
}
|
||||
writeAsarFile(fileSets, unpackedFileIndexMap) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const headerPickle = pickle.createEmpty();
|
||||
headerPickle.writeString(JSON.stringify(this.fs.header));
|
||||
const headerBuf = headerPickle.toBuffer();
|
||||
const sizePickle = pickle.createEmpty();
|
||||
sizePickle.writeUInt32(headerBuf.length);
|
||||
const sizeBuf = sizePickle.toBuffer();
|
||||
const writeStream = fs_2.createWriteStream(this.outFile);
|
||||
writeStream.on("error", reject);
|
||||
writeStream.on("close", resolve);
|
||||
writeStream.write(sizeBuf);
|
||||
let fileSetIndex = 0;
|
||||
let files = fileSets[0].files;
|
||||
let metadata = fileSets[0].metadata;
|
||||
let transformedFiles = fileSets[0].transformedFiles;
|
||||
let unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[0]);
|
||||
const w = (index) => {
|
||||
while (true) {
|
||||
if (index >= files.length) {
|
||||
if (++fileSetIndex >= fileSets.length) {
|
||||
writeStream.end();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
files = fileSets[fileSetIndex].files;
|
||||
metadata = fileSets[fileSetIndex].metadata;
|
||||
transformedFiles = fileSets[fileSetIndex].transformedFiles;
|
||||
unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[fileSetIndex]);
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
if (!unpackedFileIndexSet.has(index)) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
const stat = metadata.get(files[index]);
|
||||
if (stat != null && stat.isSymbolicLink()) {
|
||||
fs_2.symlink(stat.linkRelativeToFile, path.join(this.unpackedDest, stat.pathInArchive), () => w(index + 1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
async processFileSets(fileSets) {
|
||||
var _a;
|
||||
const unpackedPaths = new Set();
|
||||
if (this.config.options.smartUnpack !== false) {
|
||||
for (const fileSet of fileSets) {
|
||||
(0, unpackDetector_1.detectUnpackedDirs)(fileSet, unpackedPaths);
|
||||
}
|
||||
}
|
||||
const resultsMap = new Map();
|
||||
const streamOrdering = [];
|
||||
const normalizedUnpackedPaths = Array.from(unpackedPaths).map(p => path.normalize(p));
|
||||
// Check whether a file or directory should be unpacked, using pre-normalized unpacked paths and early returns
|
||||
const isUnpacked = (dir, file, stat) => {
|
||||
var _a, _b;
|
||||
const normalizedDir = path.normalize(dir);
|
||||
// Check file pattern first (most specific)
|
||||
if (!(0, builder_util_1.isEmptyOrSpaces)(file) && stat && ((_b = (_a = this.config).unpackPattern) === null || _b === void 0 ? void 0 : _b.call(_a, file, stat))) {
|
||||
return true;
|
||||
}
|
||||
// Check if path is within any unpacked directory
|
||||
for (const unpackedPath of normalizedUnpackedPaths) {
|
||||
if (normalizedDir === unpackedPath || normalizedDir.startsWith(unpackedPath + path.sep)) {
|
||||
return true;
|
||||
}
|
||||
const data = transformedFiles == null ? null : transformedFiles.get(index);
|
||||
const file = files[index];
|
||||
if (data !== null && data !== undefined) {
|
||||
writeStream.write(data, () => w(index + 1));
|
||||
return;
|
||||
}
|
||||
// https://github.com/yarnpkg/yarn/pull/3539
|
||||
const stat = metadata.get(file);
|
||||
if (stat != null && stat.size < 2 * 1024 * 1024) {
|
||||
promises_1.readFile(file)
|
||||
.then(it => {
|
||||
writeStream.write(it, () => w(index + 1));
|
||||
})
|
||||
.catch(e => reject(`Cannot read file ${file}: ${e.stack || e}`));
|
||||
}
|
||||
else {
|
||||
const readStream = fs_2.createReadStream(file);
|
||||
readStream.on("error", reject);
|
||||
readStream.once("end", () => w(index + 1));
|
||||
readStream.on("open", () => {
|
||||
readStream.pipe(writeStream, {
|
||||
end: false,
|
||||
});
|
||||
});
|
||||
}
|
||||
return false;
|
||||
};
|
||||
// First pass: process all files in order, ensuring parent directories exist
|
||||
for (const fileSet of fileSets) {
|
||||
// Don't use Promise.all, we need to retain order of execution/iteration through the already-ordered fileset
|
||||
for (const [index, file] of fileSet.files.entries()) {
|
||||
const transformedData = (_a = fileSet.transformedFiles) === null || _a === void 0 ? void 0 : _a.get(index);
|
||||
const stat = fileSet.metadata.get(file);
|
||||
const destination = path.relative(this.config.defaultDestination, (0, appFileCopier_1.getDestinationPath)(file, fileSet));
|
||||
// Ensure parent directories exist before processing file
|
||||
this.ensureParentDirectories(destination, resultsMap, streamOrdering);
|
||||
const result = await this.processFileOrSymlink({
|
||||
file,
|
||||
destination,
|
||||
fileSet,
|
||||
transformedData,
|
||||
stat,
|
||||
isUnpacked,
|
||||
});
|
||||
if (result && !resultsMap.has(result.path)) {
|
||||
resultsMap.set(result.path, result);
|
||||
streamOrdering.push(result.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Second pass: propagate unpacked flag to parent directories
|
||||
for (const entry of resultsMap.values()) {
|
||||
if (entry.unpacked) {
|
||||
this.markParentDirectoriesAsUnpacked(entry.path, resultsMap, isUnpacked);
|
||||
}
|
||||
}
|
||||
// Build final results array maintaining processing order
|
||||
return streamOrdering.reduce((streams, path) => {
|
||||
const stream = resultsMap.has(path) ? resultsMap.get(path) : null;
|
||||
if (stream != null) {
|
||||
streams.push(stream);
|
||||
}
|
||||
return streams;
|
||||
}, []);
|
||||
}
|
||||
ensureParentDirectories(destination, resultsMap, streamOrdering) {
|
||||
const parents = [];
|
||||
let current = path.dirname(path.normalize(destination));
|
||||
// Collect all parent directories from deepest to root
|
||||
while (current !== ".") {
|
||||
parents.unshift(current);
|
||||
current = path.dirname(current);
|
||||
}
|
||||
// Add parent directories in order (root to deepest)
|
||||
for (const parentPath of parents) {
|
||||
if (!resultsMap.has(parentPath)) {
|
||||
const dir = {
|
||||
type: "directory",
|
||||
path: parentPath,
|
||||
unpacked: false, // Updated in second pass if needed
|
||||
};
|
||||
resultsMap.set(parentPath, dir);
|
||||
streamOrdering.push(parentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
markParentDirectoriesAsUnpacked(destination, resultsMap, isUnpacked) {
|
||||
let current = path.dirname(path.normalize(destination));
|
||||
while (current !== ".") {
|
||||
const entry = resultsMap.get(current);
|
||||
if (entry && isUnpacked(current)) {
|
||||
entry.unpacked = true;
|
||||
}
|
||||
current = path.dirname(current);
|
||||
}
|
||||
}
|
||||
async processFileOrSymlink(options) {
|
||||
const { isUnpacked, transformedData, file, destination, stat } = options;
|
||||
const unpacked = isUnpacked(destination, file, stat);
|
||||
// Handle directories
|
||||
if (!stat.isFile() && !stat.isSymbolicLink()) {
|
||||
return { path: destination, unpacked, type: "directory" };
|
||||
}
|
||||
// Handle transformed data (pre-processed content)
|
||||
if (transformedData != null) {
|
||||
const size = Buffer.byteLength(transformedData);
|
||||
return {
|
||||
path: destination,
|
||||
streamGenerator: () => new stream_1.Readable({
|
||||
read() {
|
||||
this.push(transformedData);
|
||||
this.push(null);
|
||||
},
|
||||
}),
|
||||
unpacked,
|
||||
type: "file",
|
||||
stat: { mode: stat.mode, size },
|
||||
};
|
||||
writeStream.write(headerBuf, () => w(0));
|
||||
}
|
||||
// verify that the file is not a direct link or symlinked to access/copy a system file
|
||||
await this.protectSystemAndUnsafePaths(file, await this.packager.info.getWorkspaceRoot());
|
||||
const baseConfig = {
|
||||
path: destination,
|
||||
streamGenerator: () => fs.createReadStream(file),
|
||||
unpacked,
|
||||
stat,
|
||||
};
|
||||
// Handle regular files
|
||||
if (!stat.isSymbolicLink()) {
|
||||
return { ...baseConfig, type: "file" };
|
||||
}
|
||||
// Handle symlinks - make relative to source location
|
||||
let link = await (0, fs_extra_1.readlink)(file);
|
||||
if (path.isAbsolute(link)) {
|
||||
link = path.relative(path.dirname(file), link);
|
||||
}
|
||||
return {
|
||||
...baseConfig,
|
||||
type: "link",
|
||||
symlink: link,
|
||||
};
|
||||
}
|
||||
orderFileSet(fileSet) {
|
||||
const sortedFileEntries = Array.from(fileSet.files.entries());
|
||||
sortedFileEntries.sort(([, a], [, b]) => {
|
||||
if (a === b) {
|
||||
return 0;
|
||||
}
|
||||
// Place addons last because their signature changes per build
|
||||
const isAAddon = a.endsWith(".node");
|
||||
const isBAddon = b.endsWith(".node");
|
||||
if (isAAddon && !isBAddon) {
|
||||
return 1;
|
||||
}
|
||||
if (isBAddon && !isAAddon) {
|
||||
return -1;
|
||||
}
|
||||
// Otherwise order by name
|
||||
return a < b ? -1 : 1;
|
||||
});
|
||||
let transformedFiles;
|
||||
if (fileSet.transformedFiles) {
|
||||
transformedFiles = new Map();
|
||||
const indexMap = new Map();
|
||||
for (const [newIndex, [oldIndex]] of sortedFileEntries.entries()) {
|
||||
indexMap.set(oldIndex, newIndex);
|
||||
}
|
||||
for (const [oldIndex, value] of fileSet.transformedFiles) {
|
||||
const newIndex = indexMap.get(oldIndex);
|
||||
if (newIndex === undefined) {
|
||||
throw new Error(`Internal error: ${fileSet.files[oldIndex]} was lost while ordering asar`);
|
||||
}
|
||||
transformedFiles.set(newIndex, value);
|
||||
}
|
||||
}
|
||||
return {
|
||||
src: fileSet.src,
|
||||
destination: fileSet.destination,
|
||||
metadata: fileSet.metadata,
|
||||
files: sortedFileEntries.map(([, file]) => file),
|
||||
transformedFiles,
|
||||
};
|
||||
}
|
||||
async checkAgainstRoots(target, allowRoots) {
|
||||
const resolved = await resolvePath(target);
|
||||
if (resolved == null || (0, builder_util_1.isEmptyOrSpaces)(resolved)) {
|
||||
return false;
|
||||
}
|
||||
for (const root of allowRoots) {
|
||||
if (resolved === root || resolved.startsWith(root + path.sep)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
async protectSystemAndUnsafePaths(file, workspaceRoot) {
|
||||
const resolved = await resolvePath(file);
|
||||
const logFields = { source: file, realPath: resolved };
|
||||
const workspace = await resolvePath(workspaceRoot);
|
||||
// If in workspace, always safe
|
||||
if (workspace && (resolved === null || resolved === void 0 ? void 0 : resolved.startsWith(workspace))) {
|
||||
return;
|
||||
}
|
||||
// Check allowlist (priority)
|
||||
if (await this.checkAgainstRoots(file, await ALLOWLIST)) {
|
||||
return;
|
||||
}
|
||||
// Check denylist
|
||||
if (await this.checkAgainstRoots(file, await DENYLIST)) {
|
||||
builder_util_1.log.error(logFields, `denied access to system or unsafe path`);
|
||||
throw new Error(`Cannot copy file [${file}] symlinked to file [${resolved}] outside the package to a system or unsafe path`);
|
||||
}
|
||||
// Default: outside explicit paths but not explicitly denied
|
||||
builder_util_1.log.debug(logFields, `path is outside of explicit safe paths, defaulting to safe`);
|
||||
}
|
||||
}
|
||||
exports.AsarPackager = AsarPackager;
|
||||
async function order(filenames, orderingFile, src) {
|
||||
const orderingFiles = (await promises_1.readFile(orderingFile, "utf8")).split("\n").map(line => {
|
||||
if (line.indexOf(":") !== -1) {
|
||||
line = line.split(":").pop();
|
||||
}
|
||||
line = line.trim();
|
||||
if (line[0] === "/") {
|
||||
line = line.slice(1);
|
||||
}
|
||||
return line;
|
||||
});
|
||||
const ordering = [];
|
||||
for (const file of orderingFiles) {
|
||||
const pathComponents = file.split(path.sep);
|
||||
for (const pathComponent of pathComponents) {
|
||||
ordering.push(path.join(src, pathComponent));
|
||||
}
|
||||
}
|
||||
const sortedFiles = [];
|
||||
let missing = 0;
|
||||
const total = filenames.length;
|
||||
for (const file of ordering) {
|
||||
if (!sortedFiles.includes(file) && filenames.includes(file)) {
|
||||
sortedFiles.push(file);
|
||||
}
|
||||
}
|
||||
for (const file of filenames) {
|
||||
if (!sortedFiles.includes(file)) {
|
||||
sortedFiles.push(file);
|
||||
missing += 1;
|
||||
}
|
||||
}
|
||||
builder_util_1.log.info({ coverage: ((total - missing) / total) * 100 }, "ordering files in ASAR archive");
|
||||
return sortedFiles;
|
||||
}
|
||||
function copyFileOrData(fileCopier, data, source, destination, stats) {
|
||||
if (data == null) {
|
||||
return fileCopier.copy(source, destination, stats);
|
||||
}
|
||||
else {
|
||||
return promises_1.writeFile(destination, data);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=asarUtil.js.map
|
||||
2
electron/node_modules/app-builder-lib/out/asar/asarUtil.js.map
generated
vendored
2
electron/node_modules/app-builder-lib/out/asar/asarUtil.js.map
generated
vendored
File diff suppressed because one or more lines are too long
9
electron/node_modules/app-builder-lib/out/asar/integrity.d.ts
generated
vendored
9
electron/node_modules/app-builder-lib/out/asar/integrity.d.ts
generated
vendored
|
|
@ -1,8 +1,9 @@
|
|||
/// <reference types="node" />
|
||||
import { NodeIntegrity } from "./asar";
|
||||
import { FileMatcher } from "../fileMatcher";
|
||||
export interface AsarIntegrityOptions {
|
||||
readonly resourcesPath: string;
|
||||
readonly resourcesRelativePath: string;
|
||||
readonly resourcesDestinationPath: string;
|
||||
readonly extraResourceMatchers: Array<FileMatcher> | null;
|
||||
}
|
||||
export interface HeaderHash {
|
||||
algorithm: "SHA256";
|
||||
|
|
@ -11,6 +12,4 @@ export interface HeaderHash {
|
|||
export interface AsarIntegrity {
|
||||
[key: string]: HeaderHash;
|
||||
}
|
||||
export declare function computeData({ resourcesPath, resourcesRelativePath }: AsarIntegrityOptions): Promise<AsarIntegrity>;
|
||||
export declare function hashFile(file: string, blockSize?: number): Promise<NodeIntegrity>;
|
||||
export declare function hashFileContents(contents: Buffer | string, blockSize?: number): NodeIntegrity;
|
||||
export declare function computeData({ resourcesPath, resourcesRelativePath, resourcesDestinationPath, extraResourceMatchers }: AsarIntegrityOptions): Promise<AsarIntegrity>;
|
||||
|
|
|
|||
117
electron/node_modules/app-builder-lib/out/asar/integrity.js
generated
vendored
117
electron/node_modules/app-builder-lib/out/asar/integrity.js
generated
vendored
|
|
@ -1,89 +1,62 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hashFileContents = exports.hashFile = exports.computeData = void 0;
|
||||
const bluebird_lst_1 = require("bluebird-lst");
|
||||
exports.computeData = computeData;
|
||||
const builder_util_1 = require("builder-util");
|
||||
const crypto_1 = require("crypto");
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const path = require("path");
|
||||
const asar_1 = require("./asar");
|
||||
async function computeData({ resourcesPath, resourcesRelativePath }) {
|
||||
async function computeData({ resourcesPath, resourcesRelativePath, resourcesDestinationPath, extraResourceMatchers }) {
|
||||
const isAsar = (filepath) => filepath.endsWith(".asar");
|
||||
const resources = await (0, promises_1.readdir)(resourcesPath);
|
||||
const resourceAsars = resources.filter(isAsar).reduce((prev, filename) => ({
|
||||
...prev,
|
||||
[path.join(resourcesRelativePath, filename)]: path.join(resourcesPath, filename),
|
||||
}), {});
|
||||
const extraResources = await Promise.all((extraResourceMatchers !== null && extraResourceMatchers !== void 0 ? extraResourceMatchers : []).map(async (matcher) => {
|
||||
const { from, to } = matcher;
|
||||
const stat = await (0, builder_util_1.statOrNull)(from);
|
||||
if (stat == null) {
|
||||
builder_util_1.log.warn({ from }, `file source doesn't exist`);
|
||||
return [];
|
||||
}
|
||||
if (stat.isFile()) {
|
||||
return [{ from, to }];
|
||||
}
|
||||
if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
|
||||
matcher.prependPattern("**/*");
|
||||
}
|
||||
const matcherFilter = matcher.createFilter();
|
||||
const extraResourceMatches = await (0, builder_util_1.walk)(matcher.from, (file, stats) => matcherFilter(file, stats) || stats.isDirectory());
|
||||
return extraResourceMatches.map(from => ({ from, to: matcher.to }));
|
||||
}));
|
||||
const extraResourceAsars = extraResources
|
||||
.flat(1)
|
||||
.filter(match => isAsar(match.from))
|
||||
.reduce((prev, { to, from }) => {
|
||||
const prefix = path.relative(resourcesDestinationPath, to);
|
||||
return {
|
||||
...prev,
|
||||
[path.join(resourcesRelativePath, prefix, path.basename(from))]: from,
|
||||
};
|
||||
}, {});
|
||||
// sort to produce constant result
|
||||
const names = (await promises_1.readdir(resourcesPath)).filter(it => it.endsWith(".asar")).sort();
|
||||
const checksums = await bluebird_lst_1.default.map(names, it => hashHeader(path.join(resourcesPath, it)));
|
||||
const result = {};
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
result[path.join(resourcesRelativePath, names[i])] = checksums[i];
|
||||
const allAsars = [...Object.entries(resourceAsars), ...Object.entries(extraResourceAsars)].sort(([name1], [name2]) => name1.localeCompare(name2));
|
||||
const hashes = await Promise.all(allAsars.map(async ([, from]) => hashHeader(from)));
|
||||
const asarIntegrity = {};
|
||||
for (let i = 0; i < allAsars.length; i++) {
|
||||
const [asar] = allAsars[i];
|
||||
asarIntegrity[asar] = hashes[i];
|
||||
}
|
||||
return result;
|
||||
return asarIntegrity;
|
||||
}
|
||||
exports.computeData = computeData;
|
||||
async function hashHeader(file) {
|
||||
const hash = crypto_1.createHash("sha256");
|
||||
const { header } = await asar_1.readAsarHeader(file);
|
||||
const hash = (0, crypto_1.createHash)("sha256");
|
||||
const { header } = await (0, asar_1.readAsarHeader)(file);
|
||||
hash.update(header);
|
||||
return {
|
||||
algorithm: "SHA256",
|
||||
hash: hash.digest("hex"),
|
||||
};
|
||||
}
|
||||
function hashFile(file, blockSize = 4 * 1024 * 1024) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hash = crypto_1.createHash("sha256");
|
||||
const blocks = new Array();
|
||||
let blockBytes = 0;
|
||||
let blockHash = crypto_1.createHash("sha256");
|
||||
function updateBlockHash(chunk) {
|
||||
let off = 0;
|
||||
while (off < chunk.length) {
|
||||
const toHash = Math.min(blockSize - blockBytes, chunk.length - off);
|
||||
blockHash.update(chunk.slice(off, off + toHash));
|
||||
off += toHash;
|
||||
blockBytes += toHash;
|
||||
if (blockBytes === blockSize) {
|
||||
blocks.push(blockHash.digest("hex"));
|
||||
blockHash = crypto_1.createHash("sha256");
|
||||
blockBytes = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
fs_1.createReadStream(file)
|
||||
.on("data", it => {
|
||||
// Note that `it` is a Buffer anyway so this cast is a no-op
|
||||
updateBlockHash(Buffer.from(it));
|
||||
hash.update(it);
|
||||
})
|
||||
.on("error", reject)
|
||||
.on("end", () => {
|
||||
if (blockBytes !== 0) {
|
||||
blocks.push(blockHash.digest("hex"));
|
||||
}
|
||||
resolve({
|
||||
algorithm: "SHA256",
|
||||
hash: hash.digest("hex"),
|
||||
blockSize,
|
||||
blocks,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.hashFile = hashFile;
|
||||
function hashFileContents(contents, blockSize = 4 * 1024 * 1024) {
|
||||
const buffer = Buffer.from(contents);
|
||||
const hash = crypto_1.createHash("sha256");
|
||||
hash.update(buffer);
|
||||
const blocks = new Array();
|
||||
for (let off = 0; off < buffer.length; off += blockSize) {
|
||||
const blockHash = crypto_1.createHash("sha256");
|
||||
blockHash.update(buffer.slice(off, off + blockSize));
|
||||
blocks.push(blockHash.digest("hex"));
|
||||
}
|
||||
return {
|
||||
algorithm: "SHA256",
|
||||
hash: hash.digest("hex"),
|
||||
blockSize,
|
||||
blocks,
|
||||
};
|
||||
}
|
||||
exports.hashFileContents = hashFileContents;
|
||||
//# sourceMappingURL=integrity.js.map
|
||||
2
electron/node_modules/app-builder-lib/out/asar/integrity.js.map
generated
vendored
2
electron/node_modules/app-builder-lib/out/asar/integrity.js.map
generated
vendored
File diff suppressed because one or more lines are too long
95
electron/node_modules/app-builder-lib/out/asar/unpackDetector.js
generated
vendored
95
electron/node_modules/app-builder-lib/out/asar/unpackDetector.js
generated
vendored
|
|
@ -1,108 +1,43 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.detectUnpackedDirs = exports.isLibOrExe = void 0;
|
||||
const bluebird_lst_1 = require("bluebird-lst");
|
||||
exports.isLibOrExe = isLibOrExe;
|
||||
exports.detectUnpackedDirs = detectUnpackedDirs;
|
||||
const builder_util_1 = require("builder-util");
|
||||
const fs_1 = require("builder-util/out/fs");
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const isbinaryfile_1 = require("isbinaryfile");
|
||||
const path = require("path");
|
||||
const fileTransformer_1 = require("../fileTransformer");
|
||||
const appFileCopier_1 = require("../util/appFileCopier");
|
||||
function addValue(map, key, value) {
|
||||
let list = map.get(key);
|
||||
if (list == null) {
|
||||
list = [value];
|
||||
map.set(key, list);
|
||||
}
|
||||
else {
|
||||
list.push(value);
|
||||
}
|
||||
}
|
||||
function isLibOrExe(file) {
|
||||
return file.endsWith(".dll") || file.endsWith(".exe") || file.endsWith(".dylib") || file.endsWith(".so");
|
||||
// https://github.com/electron-userland/electron-builder/issues/3038
|
||||
return file.endsWith(".dll") || file.endsWith(".exe") || file.endsWith(".dylib") || file.endsWith(".so") || file.endsWith(".node");
|
||||
}
|
||||
exports.isLibOrExe = isLibOrExe;
|
||||
/** @internal */
|
||||
async function detectUnpackedDirs(fileSet, autoUnpackDirs, unpackedDest, rootForAppFilesWithoutAsar) {
|
||||
const dirToCreate = new Map();
|
||||
function detectUnpackedDirs(fileSet, autoUnpackDirs) {
|
||||
const metadata = fileSet.metadata;
|
||||
function addParents(child, root) {
|
||||
child = path.dirname(child);
|
||||
if (autoUnpackDirs.has(child)) {
|
||||
return;
|
||||
}
|
||||
do {
|
||||
autoUnpackDirs.add(child);
|
||||
const p = path.dirname(child);
|
||||
// create parent dir to be able to copy file later without directory existence check
|
||||
addValue(dirToCreate, p, path.basename(child));
|
||||
if (child === root || p === root || autoUnpackDirs.has(p)) {
|
||||
break;
|
||||
}
|
||||
child = p;
|
||||
} while (true);
|
||||
autoUnpackDirs.add(root);
|
||||
}
|
||||
for (let i = 0, n = fileSet.files.length; i < n; i++) {
|
||||
const file = fileSet.files[i];
|
||||
const index = file.lastIndexOf(fileTransformer_1.NODE_MODULES_PATTERN);
|
||||
if (index < 0) {
|
||||
const stat = metadata.get(file);
|
||||
if (!stat.moduleRootPath || autoUnpackDirs.has(stat.moduleRootPath)) {
|
||||
continue;
|
||||
}
|
||||
let nextSlashIndex = file.indexOf(path.sep, index + fileTransformer_1.NODE_MODULES_PATTERN.length + 1);
|
||||
if (nextSlashIndex < 0) {
|
||||
continue;
|
||||
}
|
||||
if (file[index + fileTransformer_1.NODE_MODULES_PATTERN.length] === "@") {
|
||||
nextSlashIndex = file.indexOf(path.sep, nextSlashIndex + 1);
|
||||
}
|
||||
if (!metadata.get(file).isFile()) {
|
||||
continue;
|
||||
}
|
||||
const packageDir = file.substring(0, nextSlashIndex);
|
||||
const packageDirPathInArchive = path.relative(rootForAppFilesWithoutAsar, appFileCopier_1.getDestinationPath(packageDir, fileSet));
|
||||
const pathInArchive = path.relative(rootForAppFilesWithoutAsar, appFileCopier_1.getDestinationPath(file, fileSet));
|
||||
if (autoUnpackDirs.has(packageDirPathInArchive)) {
|
||||
// if package dir is unpacked, any file also unpacked
|
||||
addParents(pathInArchive, packageDirPathInArchive);
|
||||
if (!stat.isFile()) {
|
||||
continue;
|
||||
}
|
||||
// https://github.com/electron-userland/electron-builder/issues/2679
|
||||
let shouldUnpack = false;
|
||||
// ffprobe-static and ffmpeg-static are known packages to always unpack
|
||||
const moduleName = path.basename(packageDir);
|
||||
const moduleName = stat.moduleName;
|
||||
const fileBaseName = path.basename(file);
|
||||
const hasExtension = path.extname(fileBaseName);
|
||||
if (moduleName === "ffprobe-static" || moduleName === "ffmpeg-static" || isLibOrExe(file)) {
|
||||
shouldUnpack = true;
|
||||
}
|
||||
else if (!file.includes(".", nextSlashIndex)) {
|
||||
shouldUnpack = !!isbinaryfile_1.isBinaryFileSync(file);
|
||||
else if (!hasExtension) {
|
||||
shouldUnpack = !!(0, isbinaryfile_1.isBinaryFileSync)(file);
|
||||
}
|
||||
if (!shouldUnpack) {
|
||||
continue;
|
||||
}
|
||||
if (builder_util_1.log.isDebugEnabled) {
|
||||
builder_util_1.log.debug({ file: pathInArchive, reason: "contains executable code" }, "not packed into asar archive");
|
||||
}
|
||||
addParents(pathInArchive, packageDirPathInArchive);
|
||||
}
|
||||
if (dirToCreate.size > 0) {
|
||||
await fs_extra_1.mkdir(`${unpackedDest + path.sep}node_modules`, { recursive: true });
|
||||
// child directories should be not created asynchronously - parent directories should be created first
|
||||
await bluebird_lst_1.default.map(dirToCreate.keys(), async (parentDir) => {
|
||||
const base = unpackedDest + path.sep + parentDir;
|
||||
await fs_extra_1.mkdir(base, { recursive: true });
|
||||
await bluebird_lst_1.default.each(dirToCreate.get(parentDir), (it) => {
|
||||
if (dirToCreate.has(parentDir + path.sep + it)) {
|
||||
// already created
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return fs_extra_1.mkdir(base + path.sep + it, { recursive: true });
|
||||
}
|
||||
});
|
||||
}, fs_1.CONCURRENCY);
|
||||
builder_util_1.log.debug({ file: stat.moduleFullFilePath, reason: "contains executable code" }, "not packed into asar archive");
|
||||
autoUnpackDirs.add(stat.moduleRootPath);
|
||||
}
|
||||
}
|
||||
exports.detectUnpackedDirs = detectUnpackedDirs;
|
||||
//# sourceMappingURL=unpackDetector.js.map
|
||||
2
electron/node_modules/app-builder-lib/out/asar/unpackDetector.js.map
generated
vendored
2
electron/node_modules/app-builder-lib/out/asar/unpackDetector.js.map
generated
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue