app-builder-lib 26.17.0 → 26.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/asar/asarUtil.js +7 -2
- package/out/asar/asarUtil.js.map +1 -1
- package/out/codeSign/windowsSignToolManager.d.ts +11 -0
- package/out/codeSign/windowsSignToolManager.js +26 -14
- package/out/codeSign/windowsSignToolManager.js.map +1 -1
- package/out/electron/ElectronFramework.d.ts +15 -0
- package/out/electron/ElectronFramework.js +36 -2
- package/out/electron/ElectronFramework.js.map +1 -1
- package/out/electron/electronMac.js +2 -28
- package/out/electron/electronMac.js.map +1 -1
- package/out/electron/electronMacUtils.d.ts +8 -0
- package/out/electron/electronMacUtils.js +40 -0
- package/out/electron/electronMacUtils.js.map +1 -0
- package/out/forge-maker.d.ts +64 -0
- package/out/forge-maker.js +108 -2
- package/out/forge-maker.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +3 -1
- package/out/index.js.map +1 -1
- package/out/node-module-collector/pnpmNodeModulesCollector.d.ts +37 -0
- package/out/node-module-collector/pnpmNodeModulesCollector.js +102 -24
- package/out/node-module-collector/pnpmNodeModulesCollector.js.map +1 -1
- package/out/options/winOptions.d.ts +2 -1
- package/out/options/winOptions.js.map +1 -1
- package/out/targets/archive.d.ts +6 -0
- package/out/targets/archive.js +12 -2
- package/out/targets/archive.js.map +1 -1
- package/out/targets/blockmap/blockmap.d.ts +43 -3
- package/out/targets/blockmap/blockmap.js +143 -16
- package/out/targets/blockmap/blockmap.js.map +1 -1
- package/out/targets/blockmap/verbatimRange.d.ts +43 -0
- package/out/targets/blockmap/verbatimRange.js +122 -0
- package/out/targets/blockmap/verbatimRange.js.map +1 -0
- package/out/targets/differentialUpdateInfoBuilder.d.ts +27 -2
- package/out/targets/differentialUpdateInfoBuilder.js +81 -5
- package/out/targets/differentialUpdateInfoBuilder.js.map +1 -1
- package/out/targets/nsis/NsisTarget.d.ts +35 -2
- package/out/targets/nsis/NsisTarget.js +121 -29
- package/out/targets/nsis/NsisTarget.js.map +1 -1
- package/out/targets/nsis/nsisOptions.d.ts +8 -3
- package/out/targets/nsis/nsisOptions.js.map +1 -1
- package/out/targets/nsis/nsisUtil.d.ts +7 -0
- package/out/targets/nsis/nsisUtil.js +14 -3
- package/out/targets/nsis/nsisUtil.js.map +1 -1
- package/out/targets/snap/core24.d.ts +2 -0
- package/out/targets/snap/core24.js +30 -7
- package/out/targets/snap/core24.js.map +1 -1
- package/out/targets/snap/coreLegacy.js +1 -2
- package/out/targets/snap/coreLegacy.js.map +1 -1
- package/out/util/appFileCopier.js +1 -1
- package/out/util/appFileCopier.js.map +1 -1
- package/out/version.d.ts +1 -1
- package/out/version.js +1 -1
- package/out/version.js.map +1 -1
- package/package.json +11 -9
- package/scheme.json +6 -6
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareVerbatimNeedle = prepareVerbatimNeedle;
|
|
4
|
+
exports.findVerbatimRange = findVerbatimRange;
|
|
5
|
+
exports.findPreparedVerbatimRange = findPreparedVerbatimRange;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
/** Bytes of the needle used as the cheap scan probe; a full hash comparison confirms every probe hit. */
|
|
10
|
+
const PROBE_SIZE = 64 * 1024;
|
|
11
|
+
/** Haystack read granularity. Peak memory ≈ READ_CHUNK_SIZE + PROBE_SIZE, independent of file sizes. */
|
|
12
|
+
const READ_CHUNK_SIZE = 1024 * 1024;
|
|
13
|
+
async function hashRange(file, start, size) {
|
|
14
|
+
const hash = (0, crypto_1.createHash)("sha256");
|
|
15
|
+
await new Promise((resolve, reject) => {
|
|
16
|
+
(0, fs_1.createReadStream)(file, { start, end: start + size - 1 })
|
|
17
|
+
.on("data", chunk => hash.update(chunk))
|
|
18
|
+
.on("end", resolve)
|
|
19
|
+
.on("error", reject);
|
|
20
|
+
});
|
|
21
|
+
return hash.digest("hex");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads what `findPreparedVerbatimRange` needs to know about `needleFile`.
|
|
25
|
+
* @throws when the needle is empty — an empty range is meaningless as a blockmap region.
|
|
26
|
+
*/
|
|
27
|
+
async function prepareVerbatimNeedle(needleFile) {
|
|
28
|
+
const size = (await (0, promises_1.stat)(needleFile)).size;
|
|
29
|
+
if (size === 0) {
|
|
30
|
+
throw new Error(`Cannot locate an empty file (${needleFile}) inside another file`);
|
|
31
|
+
}
|
|
32
|
+
const probeSize = Math.min(PROBE_SIZE, size);
|
|
33
|
+
const probe = Buffer.allocUnsafe(probeSize);
|
|
34
|
+
const needleHandle = await (0, promises_1.open)(needleFile, "r");
|
|
35
|
+
try {
|
|
36
|
+
const { bytesRead } = await needleHandle.read(probe, 0, probeSize, 0);
|
|
37
|
+
if (bytesRead !== probeSize) {
|
|
38
|
+
throw new Error(`Short read of ${needleFile}: expected ${probeSize} bytes, got ${bytesRead}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
await needleHandle.close();
|
|
43
|
+
}
|
|
44
|
+
return { file: needleFile, size, hash: await hashRange(needleFile, 0, size), probe };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Finds the first byte range of `haystackFile` whose contents are exactly the contents of `needleFile`
|
|
48
|
+
* (e.g. the location of an archive member stored with `Copy` inside an installer that embeds the archive).
|
|
49
|
+
*
|
|
50
|
+
* Streams the haystack in `READ_CHUNK_SIZE` reads (never loads it whole), scanning for the first
|
|
51
|
+
* `min(PROBE_SIZE, needle size)` bytes of the needle — with a `probe.length - 1` byte overlap between
|
|
52
|
+
* reads so a probe straddling a chunk boundary is still seen — and confirms each probe hit by hashing the
|
|
53
|
+
* candidate haystack range against the needle's hash. False-positive probe hits are skipped and the scan
|
|
54
|
+
* continues; the first confirmed match at or after `startOffset` is returned. Passing the end of an
|
|
55
|
+
* earlier match as `startOffset` finds the next occurrence, which is how identical members (e.g. the
|
|
56
|
+
* same asar packaged for several archs) are each given their own range.
|
|
57
|
+
*
|
|
58
|
+
* Reads the needle on every call; a caller searching for the same needle repeatedly should prepare it
|
|
59
|
+
* once with `prepareVerbatimNeedle` and use `findPreparedVerbatimRange`.
|
|
60
|
+
*
|
|
61
|
+
* @returns the confirmed range, or `null` when the needle does not occur verbatim at or after
|
|
62
|
+
* `startOffset` (including when it is larger than the haystack).
|
|
63
|
+
* @throws when the needle is empty — an empty range is meaningless as a blockmap region.
|
|
64
|
+
*/
|
|
65
|
+
async function findVerbatimRange(haystackFile, needleFile, startOffset = 0) {
|
|
66
|
+
return findPreparedVerbatimRange(haystackFile, await prepareVerbatimNeedle(needleFile), startOffset);
|
|
67
|
+
}
|
|
68
|
+
/** `findVerbatimRange` for a needle prepared with `prepareVerbatimNeedle`. */
|
|
69
|
+
async function findPreparedVerbatimRange(haystackFile, needle, startOffset = 0) {
|
|
70
|
+
if (!Number.isSafeInteger(startOffset) || startOffset < 0) {
|
|
71
|
+
throw new Error(`startOffset must be a non-negative integer, got ${String(startOffset)}`);
|
|
72
|
+
}
|
|
73
|
+
const { size: needleSize, probe, hash: needleHash } = needle;
|
|
74
|
+
const probeSize = probe.length;
|
|
75
|
+
const haystackSize = (await (0, promises_1.stat)(haystackFile)).size;
|
|
76
|
+
if (startOffset + needleSize > haystackSize) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const haystackHandle = await (0, promises_1.open)(haystackFile, "r");
|
|
80
|
+
try {
|
|
81
|
+
const readBuffer = Buffer.allocUnsafe(READ_CHUNK_SIZE);
|
|
82
|
+
// `carry` holds the last `probe.length - 1` bytes of the previous window so a probe occurrence that
|
|
83
|
+
// straddles two reads is found; a probe can never fit entirely inside the carry, so no hit is reported twice.
|
|
84
|
+
let carry = Buffer.alloc(0);
|
|
85
|
+
// Absolute haystack offset of window[0].
|
|
86
|
+
let windowOffset = startOffset;
|
|
87
|
+
let readPosition = startOffset;
|
|
88
|
+
while (readPosition < haystackSize) {
|
|
89
|
+
const { bytesRead } = await haystackHandle.read(readBuffer, 0, READ_CHUNK_SIZE, readPosition);
|
|
90
|
+
if (bytesRead === 0) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
readPosition += bytesRead;
|
|
94
|
+
const window = carry.length === 0 ? readBuffer.subarray(0, bytesRead) : Buffer.concat([carry, readBuffer.subarray(0, bytesRead)]);
|
|
95
|
+
let searchFrom = 0;
|
|
96
|
+
while (searchFrom <= window.length - probeSize) {
|
|
97
|
+
const index = window.indexOf(probe, searchFrom);
|
|
98
|
+
if (index === -1) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const offset = windowOffset + index;
|
|
102
|
+
if (offset + needleSize > haystackSize) {
|
|
103
|
+
// no later candidate can fit either
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if ((await hashRange(haystackFile, offset, needleSize)) === needleHash) {
|
|
107
|
+
return { offset, size: needleSize };
|
|
108
|
+
}
|
|
109
|
+
searchFrom = index + 1;
|
|
110
|
+
}
|
|
111
|
+
const carrySize = Math.min(probeSize - 1, window.length);
|
|
112
|
+
// copy: `window` may alias `readBuffer`, which the next read overwrites
|
|
113
|
+
carry = Buffer.from(window.subarray(window.length - carrySize));
|
|
114
|
+
windowOffset += window.length - carrySize;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
await haystackHandle.close();
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=verbatimRange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verbatimRange.js","sourceRoot":"","sources":["../../../src/targets/blockmap/verbatimRange.ts"],"names":[],"mappings":";;AA0CA,sDAiBC;AAqBD,8CAEC;AAGD,8DAsDC;AA3ID,mCAAmC;AACnC,2BAAqC;AAC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;gBACnC,IAAI,MAAM,GAAG,UAAU,GAAG,YAAY,EAAE,CAAC;oBACvC,oCAAoC;oBACpC,OAAO,IAAI,CAAA;gBACb,CAAC;gBACD,IAAI,CAAC,MAAM,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;oBACvE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;gBACrC,CAAC;gBACD,UAAU,GAAG,KAAK,GAAG,CAAC,CAAA;YACxB,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;YACxD,wEAAwE;YACxE,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;YAC/D,YAAY,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,CAAA;QAC3C,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,cAAc,CAAC,KAAK,EAAE,CAAA;IAC9B,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport { open, stat } from \"fs/promises\"\n\n/** Bytes of the needle used as the cheap scan probe; a full hash comparison confirms every probe hit. */\nconst PROBE_SIZE = 64 * 1024\n/** Haystack read granularity. Peak memory ≈ READ_CHUNK_SIZE + PROBE_SIZE, independent of file sizes. */\nconst READ_CHUNK_SIZE = 1024 * 1024\n\nexport interface VerbatimRange {\n offset: number\n size: number\n}\n\nasync function hashRange(file: string, start: number, size: number): Promise<string> {\n const hash = createHash(\"sha256\")\n await new Promise<void>((resolve, reject) => {\n createReadStream(file, { start, end: start + size - 1 })\n .on(\"data\", chunk => hash.update(chunk))\n .on(\"end\", resolve)\n .on(\"error\", reject)\n })\n return hash.digest(\"hex\")\n}\n\n/**\n * A needle prepared for `findPreparedVerbatimRange`: its scan probe and full hash, computed once so a\n * needle searched for several times (e.g. resumed past an earlier occurrence) is read only once.\n */\nexport interface VerbatimNeedle {\n readonly file: string\n readonly size: number\n /** sha256 of the whole needle; also what identifies byte-identical needles. */\n readonly hash: string\n /** the first `min(PROBE_SIZE, size)` bytes */\n readonly probe: Buffer\n}\n\n/**\n * Reads what `findPreparedVerbatimRange` needs to know about `needleFile`.\n * @throws when the needle is empty — an empty range is meaningless as a blockmap region.\n */\nexport async function prepareVerbatimNeedle(needleFile: string): Promise<VerbatimNeedle> {\n const size = (await stat(needleFile)).size\n if (size === 0) {\n throw new Error(`Cannot locate an empty file (${needleFile}) inside another file`)\n }\n const probeSize = Math.min(PROBE_SIZE, size)\n const probe = Buffer.allocUnsafe(probeSize)\n const needleHandle = await open(needleFile, \"r\")\n try {\n const { bytesRead } = await needleHandle.read(probe, 0, probeSize, 0)\n if (bytesRead !== probeSize) {\n throw new Error(`Short read of ${needleFile}: expected ${probeSize} bytes, got ${bytesRead}`)\n }\n } finally {\n await needleHandle.close()\n }\n return { file: needleFile, size, hash: await hashRange(needleFile, 0, size), probe }\n}\n\n/**\n * Finds the first byte range of `haystackFile` whose contents are exactly the contents of `needleFile`\n * (e.g. the location of an archive member stored with `Copy` inside an installer that embeds the archive).\n *\n * Streams the haystack in `READ_CHUNK_SIZE` reads (never loads it whole), scanning for the first\n * `min(PROBE_SIZE, needle size)` bytes of the needle — with a `probe.length - 1` byte overlap between\n * reads so a probe straddling a chunk boundary is still seen — and confirms each probe hit by hashing the\n * candidate haystack range against the needle's hash. False-positive probe hits are skipped and the scan\n * continues; the first confirmed match at or after `startOffset` is returned. Passing the end of an\n * earlier match as `startOffset` finds the next occurrence, which is how identical members (e.g. the\n * same asar packaged for several archs) are each given their own range.\n *\n * Reads the needle on every call; a caller searching for the same needle repeatedly should prepare it\n * once with `prepareVerbatimNeedle` and use `findPreparedVerbatimRange`.\n *\n * @returns the confirmed range, or `null` when the needle does not occur verbatim at or after\n * `startOffset` (including when it is larger than the haystack).\n * @throws when the needle is empty — an empty range is meaningless as a blockmap region.\n */\nexport async function findVerbatimRange(haystackFile: string, needleFile: string, startOffset = 0): Promise<VerbatimRange | null> {\n return findPreparedVerbatimRange(haystackFile, await prepareVerbatimNeedle(needleFile), startOffset)\n}\n\n/** `findVerbatimRange` for a needle prepared with `prepareVerbatimNeedle`. */\nexport async function findPreparedVerbatimRange(haystackFile: string, needle: VerbatimNeedle, startOffset = 0): Promise<VerbatimRange | null> {\n if (!Number.isSafeInteger(startOffset) || startOffset < 0) {\n throw new Error(`startOffset must be a non-negative integer, got ${String(startOffset)}`)\n }\n const { size: needleSize, probe, hash: needleHash } = needle\n const probeSize = probe.length\n const haystackSize = (await stat(haystackFile)).size\n if (startOffset + needleSize > haystackSize) {\n return null\n }\n\n const haystackHandle = await open(haystackFile, \"r\")\n try {\n const readBuffer = Buffer.allocUnsafe(READ_CHUNK_SIZE)\n // `carry` holds the last `probe.length - 1` bytes of the previous window so a probe occurrence that\n // straddles two reads is found; a probe can never fit entirely inside the carry, so no hit is reported twice.\n let carry: Buffer = Buffer.alloc(0)\n // Absolute haystack offset of window[0].\n let windowOffset = startOffset\n let readPosition = startOffset\n while (readPosition < haystackSize) {\n const { bytesRead } = await haystackHandle.read(readBuffer, 0, READ_CHUNK_SIZE, readPosition)\n if (bytesRead === 0) {\n break\n }\n readPosition += bytesRead\n const window = carry.length === 0 ? readBuffer.subarray(0, bytesRead) : Buffer.concat([carry, readBuffer.subarray(0, bytesRead)])\n\n let searchFrom = 0\n while (searchFrom <= window.length - probeSize) {\n const index = window.indexOf(probe, searchFrom)\n if (index === -1) {\n break\n }\n const offset = windowOffset + index\n if (offset + needleSize > haystackSize) {\n // no later candidate can fit either\n return null\n }\n if ((await hashRange(haystackFile, offset, needleSize)) === needleHash) {\n return { offset, size: needleSize }\n }\n searchFrom = index + 1\n }\n\n const carrySize = Math.min(probeSize - 1, window.length)\n // copy: `window` may alias `readBuffer`, which the next read overwrites\n carry = Buffer.from(window.subarray(window.length - carrySize))\n windowOffset += window.length - carrySize\n }\n } finally {\n await haystackHandle.close()\n }\n return null\n}\n"]}
|
|
@@ -2,7 +2,32 @@ import { BlockMapDataHolder, PackageFileInfo } from "builder-util-runtime";
|
|
|
2
2
|
import { Target } from "../core";
|
|
3
3
|
import { PlatformPackager } from "../platformPackager";
|
|
4
4
|
import { ArchiveOptions } from "./archive";
|
|
5
|
+
import { BlockMapRegion, BuildBlockMapOptions, ChunkerParams } from "./blockmap/blockmap";
|
|
5
6
|
export declare const BLOCK_MAP_FILE_SUFFIX = ".blockmap";
|
|
7
|
+
/**
|
|
8
|
+
* Chunker parameters for a stored (`Copy`) archive member — e.g. `resources/app.asar` when
|
|
9
|
+
* `nsis.differentialPackage` is `"store-asar"` — whose bytes sit verbatim in the artifact. Such a member
|
|
10
|
+
* changes in small, localized ways between releases, so it is chunked finer than the surrounding
|
|
11
|
+
* compressed streams to keep the differential download proportional to the change.
|
|
12
|
+
*
|
|
13
|
+
* Set by benchmark (`test/src/differentialOneLineBenchTest.ts`, 32 MB asar / 3,001 files): 4/8/16 KiB
|
|
14
|
+
* minimizes download bytes + new-blockmap bytes for a one-line edit (−5 % same-length, −17 % length-changing
|
|
15
|
+
* vs. the 8/16/32 default); anything finer is a net loss because the v2 blockmap (~22 B per block, re-downloaded
|
|
16
|
+
* in full on every update) grows faster than the block savings. `avg` must stay a power of two.
|
|
17
|
+
*/
|
|
18
|
+
export declare const STORED_MEMBER_CHUNKER: ChunkerParams;
|
|
19
|
+
/**
|
|
20
|
+
* Locates each of `memberFiles` (absolute paths of files stored verbatim inside `artifact`) and returns
|
|
21
|
+
* a `STORED_MEMBER_CHUNKER` blockmap region per located file, sorted by offset. The regions never
|
|
22
|
+
* overlap: byte-identical members (a pure-JS app packaged for x64 + arm64 has the same asar twice in
|
|
23
|
+
* the universal installer) are each matched to their own copy, and a copy already claimed by an
|
|
24
|
+
* earlier member is skipped. A member file that does not exist, or that cannot be found verbatim, is
|
|
25
|
+
* logged at warn and skipped — the blockmap then falls back to the default chunker for those bytes;
|
|
26
|
+
* it never fails the build.
|
|
27
|
+
*/
|
|
28
|
+
export declare function locateStoredMemberRegions(artifact: string, memberFiles: Array<string>): Promise<Array<BlockMapRegion>>;
|
|
29
|
+
/** `BuildBlockMapOptions` for `regions`, or `undefined` when there are none so the default chunker path is taken unchanged. */
|
|
30
|
+
export declare function toBlockMapOptions(regions: Array<BlockMapRegion>): BuildBlockMapOptions | undefined;
|
|
6
31
|
export declare function createNsisWebDifferentialUpdateInfo(artifactPath: string, packageFiles: {
|
|
7
32
|
[arch: string]: PackageFileInfo;
|
|
8
33
|
}): {
|
|
@@ -11,5 +36,5 @@ export declare function createNsisWebDifferentialUpdateInfo(artifactPath: string
|
|
|
11
36
|
};
|
|
12
37
|
} | null;
|
|
13
38
|
export declare function configureDifferentialAwareArchiveOptions(archiveOptions: ArchiveOptions): ArchiveOptions;
|
|
14
|
-
export declare function appendBlockmap(file: string): Promise<BlockMapDataHolder>;
|
|
15
|
-
export declare function createBlockmap(file: string, target: Target, packager: PlatformPackager<any>, safeArtifactName: string | null): Promise<BlockMapDataHolder>;
|
|
39
|
+
export declare function appendBlockmap(file: string, options?: BuildBlockMapOptions): Promise<BlockMapDataHolder>;
|
|
40
|
+
export declare function createBlockmap(file: string, target: Target, packager: PlatformPackager<any>, safeArtifactName: string | null, options?: BuildBlockMapOptions): Promise<BlockMapDataHolder>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BLOCK_MAP_FILE_SUFFIX = void 0;
|
|
3
|
+
exports.STORED_MEMBER_CHUNKER = exports.BLOCK_MAP_FILE_SUFFIX = void 0;
|
|
4
|
+
exports.locateStoredMemberRegions = locateStoredMemberRegions;
|
|
5
|
+
exports.toBlockMapOptions = toBlockMapOptions;
|
|
4
6
|
exports.createNsisWebDifferentialUpdateInfo = createNsisWebDifferentialUpdateInfo;
|
|
5
7
|
exports.configureDifferentialAwareArchiveOptions = configureDifferentialAwareArchiveOptions;
|
|
6
8
|
exports.appendBlockmap = appendBlockmap;
|
|
@@ -8,7 +10,77 @@ exports.createBlockmap = createBlockmap;
|
|
|
8
10
|
const builder_util_1 = require("builder-util");
|
|
9
11
|
const path = require("path");
|
|
10
12
|
const blockmap_1 = require("./blockmap/blockmap");
|
|
13
|
+
const verbatimRange_1 = require("./blockmap/verbatimRange");
|
|
11
14
|
exports.BLOCK_MAP_FILE_SUFFIX = ".blockmap";
|
|
15
|
+
/**
|
|
16
|
+
* Chunker parameters for a stored (`Copy`) archive member — e.g. `resources/app.asar` when
|
|
17
|
+
* `nsis.differentialPackage` is `"store-asar"` — whose bytes sit verbatim in the artifact. Such a member
|
|
18
|
+
* changes in small, localized ways between releases, so it is chunked finer than the surrounding
|
|
19
|
+
* compressed streams to keep the differential download proportional to the change.
|
|
20
|
+
*
|
|
21
|
+
* Set by benchmark (`test/src/differentialOneLineBenchTest.ts`, 32 MB asar / 3,001 files): 4/8/16 KiB
|
|
22
|
+
* minimizes download bytes + new-blockmap bytes for a one-line edit (−5 % same-length, −17 % length-changing
|
|
23
|
+
* vs. the 8/16/32 default); anything finer is a net loss because the v2 blockmap (~22 B per block, re-downloaded
|
|
24
|
+
* in full on every update) grows faster than the block savings. `avg` must stay a power of two.
|
|
25
|
+
*/
|
|
26
|
+
exports.STORED_MEMBER_CHUNKER = { min: 4096, avg: 8192, max: 16384 };
|
|
27
|
+
/**
|
|
28
|
+
* Locates each of `memberFiles` (absolute paths of files stored verbatim inside `artifact`) and returns
|
|
29
|
+
* a `STORED_MEMBER_CHUNKER` blockmap region per located file, sorted by offset. The regions never
|
|
30
|
+
* overlap: byte-identical members (a pure-JS app packaged for x64 + arm64 has the same asar twice in
|
|
31
|
+
* the universal installer) are each matched to their own copy, and a copy already claimed by an
|
|
32
|
+
* earlier member is skipped. A member file that does not exist, or that cannot be found verbatim, is
|
|
33
|
+
* logged at warn and skipped — the blockmap then falls back to the default chunker for those bytes;
|
|
34
|
+
* it never fails the build.
|
|
35
|
+
*/
|
|
36
|
+
async function locateStoredMemberRegions(artifact, memberFiles) {
|
|
37
|
+
var _a;
|
|
38
|
+
const regions = [];
|
|
39
|
+
// Byte-identical members have identical occurrences, and the copies are claimed in ascending order,
|
|
40
|
+
// so the scan for the next member with the same content resumes where its previous copy ended instead
|
|
41
|
+
// of rescanning (and re-confirming every earlier copy) from the start of the artifact.
|
|
42
|
+
const resumeOffsetByHash = new Map();
|
|
43
|
+
for (const memberFile of memberFiles) {
|
|
44
|
+
if (!(await (0, builder_util_1.exists)(memberFile))) {
|
|
45
|
+
builder_util_1.log.warn({ artifact: builder_util_1.log.filePath(artifact), member: builder_util_1.log.filePath(memberFile) }, "stored member file does not exist; no block map region for it");
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const needle = await (0, verbatimRange_1.prepareVerbatimNeedle)(memberFile);
|
|
49
|
+
const range = await findUnclaimedVerbatimRange(artifact, needle, regions, (_a = resumeOffsetByHash.get(needle.hash)) !== null && _a !== void 0 ? _a : 0);
|
|
50
|
+
if (range == null) {
|
|
51
|
+
builder_util_1.log.warn({ artifact: builder_util_1.log.filePath(artifact), member: builder_util_1.log.filePath(memberFile) }, "stored member not found verbatim in artifact; its bytes will be chunked with the default block map parameters");
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
resumeOffsetByHash.set(needle.hash, range.offset + range.size);
|
|
55
|
+
builder_util_1.log.info({ artifact: builder_util_1.log.filePath(artifact), member: builder_util_1.log.filePath(memberFile), offset: range.offset, size: range.size }, "located stored member region for block map");
|
|
56
|
+
regions.push({ ...range, chunker: exports.STORED_MEMBER_CHUNKER });
|
|
57
|
+
}
|
|
58
|
+
return regions.sort((a, b) => a.offset - b.offset);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The first occurrence of `needle` in `artifact` at or after `startOffset` that does not overlap a
|
|
62
|
+
* range in `claimed`. An occurrence that overlaps a claimed range is another member's copy (or part of
|
|
63
|
+
* one), so the scan resumes right after that range — every candidate start before its end would
|
|
64
|
+
* overlap it too.
|
|
65
|
+
*/
|
|
66
|
+
async function findUnclaimedVerbatimRange(artifact, needle, claimed, startOffset) {
|
|
67
|
+
for (;;) {
|
|
68
|
+
const range = await (0, verbatimRange_1.findPreparedVerbatimRange)(artifact, needle, startOffset);
|
|
69
|
+
if (range == null) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const rangeEnd = range.offset + range.size;
|
|
73
|
+
const clash = claimed.find(it => range.offset < it.offset + it.size && it.offset < rangeEnd);
|
|
74
|
+
if (clash == null) {
|
|
75
|
+
return range;
|
|
76
|
+
}
|
|
77
|
+
startOffset = clash.offset + clash.size;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** `BuildBlockMapOptions` for `regions`, or `undefined` when there are none so the default chunker path is taken unchanged. */
|
|
81
|
+
function toBlockMapOptions(regions) {
|
|
82
|
+
return regions.length === 0 ? undefined : { regions };
|
|
83
|
+
}
|
|
12
84
|
function createNsisWebDifferentialUpdateInfo(artifactPath, packageFiles) {
|
|
13
85
|
if (packageFiles == null) {
|
|
14
86
|
return null;
|
|
@@ -53,20 +125,24 @@ function configureDifferentialAwareArchiveOptions(archiveOptions) {
|
|
|
53
125
|
|
|
54
126
|
*/
|
|
55
127
|
archiveOptions.dictSize = 1;
|
|
128
|
+
// At these settings 7-Zip splits LZMA2 into 4 MB blocks only with 4+ threads and writes one solid stream with fewer,
|
|
129
|
+
// where any change rewrites everything after it (measured: a 6.7 MB update became 74 MB on a 2-thread host).
|
|
130
|
+
// Pinning the size it picks with 4+ threads keeps the bytes identical on every host.
|
|
131
|
+
archiveOptions.blockSize = 4;
|
|
56
132
|
// solid compression leads to a lot of changed blocks
|
|
57
133
|
archiveOptions.solid = false;
|
|
58
134
|
// do not allow to change compression level to avoid different packages
|
|
59
135
|
archiveOptions.compression = "normal";
|
|
60
136
|
return archiveOptions;
|
|
61
137
|
}
|
|
62
|
-
async function appendBlockmap(file) {
|
|
138
|
+
async function appendBlockmap(file, options) {
|
|
63
139
|
builder_util_1.log.info({ file: builder_util_1.log.filePath(file) }, "building embedded block map");
|
|
64
|
-
return (0, blockmap_1.buildBlockMap)(file, "deflate");
|
|
140
|
+
return (0, blockmap_1.buildBlockMap)(file, "deflate", undefined, options);
|
|
65
141
|
}
|
|
66
|
-
async function createBlockmap(file, target, packager, safeArtifactName) {
|
|
142
|
+
async function createBlockmap(file, target, packager, safeArtifactName, options) {
|
|
67
143
|
const blockMapFile = `${file}${exports.BLOCK_MAP_FILE_SUFFIX}`;
|
|
68
144
|
builder_util_1.log.info({ blockMapFile: builder_util_1.log.filePath(blockMapFile) }, "building block map");
|
|
69
|
-
const updateInfo = await (0, blockmap_1.buildBlockMap)(file, "gzip", blockMapFile);
|
|
145
|
+
const updateInfo = await (0, blockmap_1.buildBlockMap)(file, "gzip", blockMapFile, options);
|
|
70
146
|
await packager.info.emitArtifactBuildCompleted({
|
|
71
147
|
file: blockMapFile,
|
|
72
148
|
safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${exports.BLOCK_MAP_FILE_SUFFIX}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"differentialUpdateInfoBuilder.js","sourceRoot":"","sources":["../../src/targets/differentialUpdateInfoBuilder.ts"],"names":[],"mappings":";;;AAUA,kFAsBC;AAED,4FA4BC;AAED,wCAGC;AAED,wCAaC;AAlFD,+CAAkC;AAElC,6BAA4B;AAI5B,kDAAmD;AAEtC,QAAA,qBAAqB,GAAG,WAAW,CAAA;AAEhD,SAAgB,mCAAmC,CAAC,YAAoB,EAAE,YAAiD;IACzH,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA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CAAA;IAC5E,MAAM,UAAU,GAAG,MAAM,IAAA,wBAAa,EAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;IAClE,MAAM,QAAQ,CAAC,IAAI,CAAC,0BAA0B,CAAC;QAC7C,IAAI,EAAE,YAAY;QAClB,gBAAgB,EAAE,gBAAgB,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,GAAG,6BAAqB,EAAE;QACjG,MAAM;QACN,IAAI,EAAE,IAAI;QACV,QAAQ;QACR,UAAU;KACX,CAAC,CAAA;IACF,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import { log } from \"builder-util\"\nimport { BlockMapDataHolder, PackageFileInfo } from \"builder-util-runtime\"\nimport * as path from \"path\"\nimport { Target } from \"../core\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { ArchiveOptions } from \"./archive\"\nimport { buildBlockMap } from \"./blockmap/blockmap\"\n\nexport const BLOCK_MAP_FILE_SUFFIX = \".blockmap\"\n\nexport function createNsisWebDifferentialUpdateInfo(artifactPath: string, packageFiles: { [arch: string]: PackageFileInfo }) {\n if (packageFiles == null) {\n return null\n }\n\n const keys = Object.keys(packageFiles)\n if (keys.length <= 0) {\n return null\n }\n\n const packages: { [arch: string]: PackageFileInfo } = {}\n for (const arch of keys) {\n const packageFileInfo = packageFiles[arch]\n const file = path.basename(packageFileInfo.path)\n packages[arch] = {\n ...packageFileInfo,\n path: file,\n // https://github.com/electron-userland/electron-builder/issues/2583\n file,\n } as any\n }\n return { packages }\n}\n\nexport function configureDifferentialAwareArchiveOptions(archiveOptions: ArchiveOptions): ArchiveOptions {\n /*\n * dict size 64 MB: Full: 33,744.88 KB, To download: 17,630.3 KB (52%)\n * dict size 16 MB: Full: 33,936.84 KB, To download: 16,175.9 KB (48%)\n * dict size 8 MB: Full: 34,187.59 KB, To download: 8,229.9 KB (24%)\n * dict size 4 MB: Full: 34,628.73 KB, To download: 3,782.97 KB (11%)\n\n as we can see, if file changed in one place, all block is invalidated (and update size approximately equals to dict size)\n\n 1 MB is used:\n\n 1MB:\n\n 2018/01/11 11:54:41:0045 File has 59 changed blocks\n 2018/01/11 11:54:41:0050 Full: 71,588.59 KB, To download: 1,243.39 KB (2%)\n\n 4MB:\n\n 2018/01/11 11:31:43:0440 Full: 70,303.55 KB, To download: 4,843.27 KB (7%)\n 2018/01/11 11:31:43:0435 File has 234 changed blocks\n\n */\n archiveOptions.dictSize = 1\n // solid compression leads to a lot of changed blocks\n archiveOptions.solid = false\n // do not allow to change compression level to avoid different packages\n archiveOptions.compression = \"normal\"\n return archiveOptions\n}\n\nexport async function appendBlockmap(file: string): Promise<BlockMapDataHolder> {\n log.info({ file: log.filePath(file) }, \"building embedded block map\")\n return buildBlockMap(file, \"deflate\")\n}\n\nexport async function createBlockmap(file: string, target: Target, packager: PlatformPackager<any>, safeArtifactName: string | null): Promise<BlockMapDataHolder> {\n const blockMapFile = `${file}${BLOCK_MAP_FILE_SUFFIX}`\n log.info({ blockMapFile: log.filePath(blockMapFile) }, \"building block map\")\n const updateInfo = await buildBlockMap(file, \"gzip\", blockMapFile)\n await packager.info.emitArtifactBuildCompleted({\n file: blockMapFile,\n safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${BLOCK_MAP_FILE_SUFFIX}`,\n target,\n arch: null,\n packager,\n updateInfo,\n })\n return updateInfo\n}\n"]}
|
|
1
|
+
{"version":3,"file":"differentialUpdateInfoBuilder.js","sourceRoot":"","sources":["../../src/targets/differentialUpdateInfoBuilder.ts"],"names":[],"mappings":";;;AAiCA,8DAyBC;AAwBD,8CAEC;AAED,kFAsBC;AAED,4FAgCC;AAED,wCAGC;AAED,wCAmBC;AAxKD,+CAA0C;AAE1C,6BAA4B;AAI5B,kDAAwG;AACxG,4DAA0H;AAE7G,QAAA,qBAAqB,GAAG,WAAW,CAAA;AAEhD;;;;;;;;;;GAUG;AACU,QAAA,qBAAqB,GAAkB,EAAE,GAAG,EAAE,I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AAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,6BAA6B,CAAC,CAAA;IACrE,OAAO,IAAA,wBAAa,EAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;AAC3D,CAAC;AAEM,KAAK,UAAU,cAAc,CAClC,IAAY,EACZ,MAAc,EACd,QAA+B,EAC/B,gBAA+B,EAC/B,OAA8B;IAE9B,MAAM,YAAY,GAAG,GAAG,IAAI,GAAG,6BAAqB,EAAE,CAAA;IACtD,kBAAG,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,kBAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,EAAE,oBAAoB,CAAC,CAAA;IAC5E,MAAM,UAAU,GAAG,MAAM,IAAA,wBAAa,EAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;IAC3E,MAAM,QAAQ,CAAC,IAAI,CAAC,0BAA0B,CAAC;QAC7C,IAAI,EAAE,YAAY;QAClB,gBAAgB,EAAE,gBAAgB,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,GAAG,6BAAqB,EAAE;QACjG,MAAM;QACN,IAAI,EAAE,IAAI;QACV,QAAQ;QACR,UAAU;KACX,CAAC,CAAA;IACF,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import { exists, log } from \"builder-util\"\nimport { BlockMapDataHolder, PackageFileInfo } from \"builder-util-runtime\"\nimport * as path from \"path\"\nimport { Target } from \"../core\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { ArchiveOptions } from \"./archive\"\nimport { BlockMapRegion, buildBlockMap, BuildBlockMapOptions, ChunkerParams } from \"./blockmap/blockmap\"\nimport { findPreparedVerbatimRange, prepareVerbatimNeedle, VerbatimNeedle, VerbatimRange } from \"./blockmap/verbatimRange\"\n\nexport const BLOCK_MAP_FILE_SUFFIX = \".blockmap\"\n\n/**\n * Chunker parameters for a stored (`Copy`) archive member — e.g. `resources/app.asar` when\n * `nsis.differentialPackage` is `\"store-asar\"` — whose bytes sit verbatim in the artifact. Such a member\n * changes in small, localized ways between releases, so it is chunked finer than the surrounding\n * compressed streams to keep the differential download proportional to the change.\n *\n * Set by benchmark (`test/src/differentialOneLineBenchTest.ts`, 32 MB asar / 3,001 files): 4/8/16 KiB\n * minimizes download bytes + new-blockmap bytes for a one-line edit (−5 % same-length, −17 % length-changing\n * vs. the 8/16/32 default); anything finer is a net loss because the v2 blockmap (~22 B per block, re-downloaded\n * in full on every update) grows faster than the block savings. `avg` must stay a power of two.\n */\nexport const STORED_MEMBER_CHUNKER: ChunkerParams = { min: 4096, avg: 8192, max: 16384 }\n\n/**\n * Locates each of `memberFiles` (absolute paths of files stored verbatim inside `artifact`) and returns\n * a `STORED_MEMBER_CHUNKER` blockmap region per located file, sorted by offset. The regions never\n * overlap: byte-identical members (a pure-JS app packaged for x64 + arm64 has the same asar twice in\n * the universal installer) are each matched to their own copy, and a copy already claimed by an\n * earlier member is skipped. A member file that does not exist, or that cannot be found verbatim, is\n * logged at warn and skipped — the blockmap then falls back to the default chunker for those bytes;\n * it never fails the build.\n */\nexport async function locateStoredMemberRegions(artifact: string, memberFiles: Array<string>): Promise<Array<BlockMapRegion>> {\n const regions: Array<BlockMapRegion> = []\n // Byte-identical members have identical occurrences, and the copies are claimed in ascending order,\n // so the scan for the next member with the same content resumes where its previous copy ended instead\n // of rescanning (and re-confirming every earlier copy) from the start of the artifact.\n const resumeOffsetByHash = new Map<string, number>()\n for (const memberFile of memberFiles) {\n if (!(await exists(memberFile))) {\n log.warn({ artifact: log.filePath(artifact), member: log.filePath(memberFile) }, \"stored member file does not exist; no block map region for it\")\n continue\n }\n const needle = await prepareVerbatimNeedle(memberFile)\n const range = await findUnclaimedVerbatimRange(artifact, needle, regions, resumeOffsetByHash.get(needle.hash) ?? 0)\n if (range == null) {\n log.warn(\n { artifact: log.filePath(artifact), member: log.filePath(memberFile) },\n \"stored member not found verbatim in artifact; its bytes will be chunked with the default block map parameters\"\n )\n continue\n }\n resumeOffsetByHash.set(needle.hash, range.offset + range.size)\n log.info({ artifact: log.filePath(artifact), member: log.filePath(memberFile), offset: range.offset, size: range.size }, \"located stored member region for block map\")\n regions.push({ ...range, chunker: STORED_MEMBER_CHUNKER })\n }\n return regions.sort((a, b) => a.offset - b.offset)\n}\n\n/**\n * The first occurrence of `needle` in `artifact` at or after `startOffset` that does not overlap a\n * range in `claimed`. An occurrence that overlaps a claimed range is another member's copy (or part of\n * one), so the scan resumes right after that range — every candidate start before its end would\n * overlap it too.\n */\nasync function findUnclaimedVerbatimRange(artifact: string, needle: VerbatimNeedle, claimed: Array<BlockMapRegion>, startOffset: number): Promise<VerbatimRange | null> {\n for (;;) {\n const range = await findPreparedVerbatimRange(artifact, needle, startOffset)\n if (range == null) {\n return null\n }\n const rangeEnd = range.offset + range.size\n const clash = claimed.find(it => range.offset < it.offset + it.size && it.offset < rangeEnd)\n if (clash == null) {\n return range\n }\n startOffset = clash.offset + clash.size\n }\n}\n\n/** `BuildBlockMapOptions` for `regions`, or `undefined` when there are none so the default chunker path is taken unchanged. */\nexport function toBlockMapOptions(regions: Array<BlockMapRegion>): BuildBlockMapOptions | undefined {\n return regions.length === 0 ? undefined : { regions }\n}\n\nexport function createNsisWebDifferentialUpdateInfo(artifactPath: string, packageFiles: { [arch: string]: PackageFileInfo }) {\n if (packageFiles == null) {\n return null\n }\n\n const keys = Object.keys(packageFiles)\n if (keys.length <= 0) {\n return null\n }\n\n const packages: { [arch: string]: PackageFileInfo } = {}\n for (const arch of keys) {\n const packageFileInfo = packageFiles[arch]\n const file = path.basename(packageFileInfo.path)\n packages[arch] = {\n ...packageFileInfo,\n path: file,\n // https://github.com/electron-userland/electron-builder/issues/2583\n file,\n } as any\n }\n return { packages }\n}\n\nexport function configureDifferentialAwareArchiveOptions(archiveOptions: ArchiveOptions): ArchiveOptions {\n /*\n * dict size 64 MB: Full: 33,744.88 KB, To download: 17,630.3 KB (52%)\n * dict size 16 MB: Full: 33,936.84 KB, To download: 16,175.9 KB (48%)\n * dict size 8 MB: Full: 34,187.59 KB, To download: 8,229.9 KB (24%)\n * dict size 4 MB: Full: 34,628.73 KB, To download: 3,782.97 KB (11%)\n\n as we can see, if file changed in one place, all block is invalidated (and update size approximately equals to dict size)\n\n 1 MB is used:\n\n 1MB:\n\n 2018/01/11 11:54:41:0045 File has 59 changed blocks\n 2018/01/11 11:54:41:0050 Full: 71,588.59 KB, To download: 1,243.39 KB (2%)\n\n 4MB:\n\n 2018/01/11 11:31:43:0440 Full: 70,303.55 KB, To download: 4,843.27 KB (7%)\n 2018/01/11 11:31:43:0435 File has 234 changed blocks\n\n */\n archiveOptions.dictSize = 1\n // At these settings 7-Zip splits LZMA2 into 4 MB blocks only with 4+ threads and writes one solid stream with fewer,\n // where any change rewrites everything after it (measured: a 6.7 MB update became 74 MB on a 2-thread host).\n // Pinning the size it picks with 4+ threads keeps the bytes identical on every host.\n archiveOptions.blockSize = 4\n // solid compression leads to a lot of changed blocks\n archiveOptions.solid = false\n // do not allow to change compression level to avoid different packages\n archiveOptions.compression = \"normal\"\n return archiveOptions\n}\n\nexport async function appendBlockmap(file: string, options?: BuildBlockMapOptions): Promise<BlockMapDataHolder> {\n log.info({ file: log.filePath(file) }, \"building embedded block map\")\n return buildBlockMap(file, \"deflate\", undefined, options)\n}\n\nexport async function createBlockmap(\n file: string,\n target: Target,\n packager: PlatformPackager<any>,\n safeArtifactName: string | null,\n options?: BuildBlockMapOptions\n): Promise<BlockMapDataHolder> {\n const blockMapFile = `${file}${BLOCK_MAP_FILE_SUFFIX}`\n log.info({ blockMapFile: log.filePath(blockMapFile) }, \"building block map\")\n const updateInfo = await buildBlockMap(file, \"gzip\", blockMapFile, options)\n await packager.info.emitArtifactBuildCompleted({\n file: blockMapFile,\n safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${BLOCK_MAP_FILE_SUFFIX}`,\n target,\n arch: null,\n packager,\n updateInfo,\n })\n return updateInfo\n}\n"]}
|
|
@@ -2,9 +2,18 @@ import { Arch } from "builder-util";
|
|
|
2
2
|
import { PackageFileInfo } from "builder-util-runtime";
|
|
3
3
|
import { Target } from "../../core";
|
|
4
4
|
import { WinPackager } from "../../winPackager";
|
|
5
|
+
import { ArchiveOptions } from "../archive";
|
|
5
6
|
import { Defines } from "./Defines";
|
|
6
7
|
import { NsisOptions } from "./nsisOptions";
|
|
7
8
|
import { AppPackageHelper, CopyElevateHelper } from "./nsisUtil";
|
|
9
|
+
/** The member `differentialPackage: "store-asar"` keeps uncompressed in the app package, relative to the unpacked app dir. */
|
|
10
|
+
export declare const STORED_ASAR_PATH = "resources/app.asar";
|
|
11
|
+
/**
|
|
12
|
+
* The `archive()` options `buildAppPackage` packages the unpacked app with, before the differential-aware
|
|
13
|
+
* adjustments of `configureDifferentialAwareArchiveOptions`. Exported so the benchmark
|
|
14
|
+
* (`test/src/differentialOneLineBenchTest.ts`) packages exactly like a real build instead of copying these.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createAppPackageArchiveOptions(compression: ArchiveOptions["compression"], excluded: Array<string> | null, storedPaths: Array<string> | null): ArchiveOptions;
|
|
8
17
|
export declare class NsisTarget extends Target {
|
|
9
18
|
readonly packager: WinPackager;
|
|
10
19
|
readonly outDir: string;
|
|
@@ -17,9 +26,33 @@ export declare class NsisTarget extends Target {
|
|
|
17
26
|
get shouldBuildUniversalInstaller(): boolean;
|
|
18
27
|
build(appOutDir: string, arch: Arch): Promise<any>;
|
|
19
28
|
get isBuildDifferentialAware(): boolean;
|
|
29
|
+
private get isZipPayload();
|
|
30
|
+
private get isStoreAsar();
|
|
31
|
+
/**
|
|
32
|
+
* Everything that makes buildAppPackage's archive differ between targets. Targets sharing an
|
|
33
|
+
* AppPackageHelper (nsis + portable) reuse one app package per arch only when this key matches,
|
|
34
|
+
* so a target never embeds an archive whose format or layout was chosen by another target.
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
get appPackageCacheKey(): string;
|
|
20
38
|
private getPreCompressedFileExtensions;
|
|
21
|
-
/**
|
|
22
|
-
|
|
39
|
+
/**
|
|
40
|
+
* @private
|
|
41
|
+
* @returns the package file info plus the absolute source paths of the members stored verbatim in it
|
|
42
|
+
* (`storedMemberFiles`, empty unless `differentialPackage` is `"store-asar"`).
|
|
43
|
+
*/
|
|
44
|
+
buildAppPackage(appOutDir: string, arch: Arch, elevateHelper?: CopyElevateHelper | null, fileNameSuffix?: string): Promise<{
|
|
45
|
+
fileInfo: PackageFileInfo;
|
|
46
|
+
storedMemberFiles: Array<string>;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* `archive()` silently skips stored paths that don't exist, so without an asar (e.g. `asar: false`)
|
|
50
|
+
* "store-asar" would do nothing unnoticed. The fallback is harmless — the differential package is
|
|
51
|
+
* non-solid, so each unpacked file is already its own block — but say so once per target.
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
warnIfStoreAsarHasNoAsar(appOutDir: string): Promise<void>;
|
|
55
|
+
private storeAsarChecked;
|
|
23
56
|
protected installerFilenamePattern(primaryArch?: Arch | null, defaultArch?: string): string;
|
|
24
57
|
private get isPortable();
|
|
25
58
|
finishBuild(): Promise<any>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NsisTarget = void 0;
|
|
3
|
+
exports.NsisTarget = exports.STORED_ASAR_PATH = void 0;
|
|
4
|
+
exports.createAppPackageArchiveOptions = createAppPackageArchiveOptions;
|
|
4
5
|
const builder_util_1 = require("builder-util");
|
|
5
6
|
const builder_util_runtime_1 = require("builder-util-runtime");
|
|
6
7
|
const debug_1 = require("debug");
|
|
@@ -24,6 +25,26 @@ const nsisUtil_1 = require("./nsisUtil");
|
|
|
24
25
|
const nsisValidation_1 = require("./nsisValidation");
|
|
25
26
|
const WineVm_1 = require("../../vm/WineVm");
|
|
26
27
|
const debug = (0, debug_1.default)("electron-builder:nsis");
|
|
28
|
+
/** The member `differentialPackage: "store-asar"` keeps uncompressed in the app package, relative to the unpacked app dir. */
|
|
29
|
+
exports.STORED_ASAR_PATH = "resources/app.asar";
|
|
30
|
+
/**
|
|
31
|
+
* The `archive()` options `buildAppPackage` packages the unpacked app with, before the differential-aware
|
|
32
|
+
* adjustments of `configureDifferentialAwareArchiveOptions`. Exported so the benchmark
|
|
33
|
+
* (`test/src/differentialOneLineBenchTest.ts`) packages exactly like a real build instead of copying these.
|
|
34
|
+
*/
|
|
35
|
+
function createAppPackageArchiveOptions(compression, excluded, storedPaths) {
|
|
36
|
+
return {
|
|
37
|
+
withoutDir: true,
|
|
38
|
+
compression,
|
|
39
|
+
// The install-time Nsis7z extractor only decodes plain LZMA2/Copy and single-stream BCJ — not
|
|
40
|
+
// the CPU branch converters modern 7za applies to executables (BCJ2 on x86/x64, ARM64 on
|
|
41
|
+
// arm64), which it silently skips, dropping the main exe and every native binary from the
|
|
42
|
+
// install. Pin the payload to a filter it can decode. See #9983.
|
|
43
|
+
installTimeDecodable: true,
|
|
44
|
+
excluded,
|
|
45
|
+
storedPaths,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
27
48
|
// noinspection SpellCheckingInspection
|
|
28
49
|
const ELECTRON_BUILDER_NS_UUID = builder_util_runtime_1.UUID.parse("50e065bc-3134-11e6-9bab-38c9862bdaf3");
|
|
29
50
|
const USE_NSIS_BUILT_IN_COMPRESSOR = false;
|
|
@@ -36,6 +57,7 @@ class NsisTarget extends core_1.Target {
|
|
|
36
57
|
/** @private */
|
|
37
58
|
this.archs = new Map();
|
|
38
59
|
this.isAsyncSupported = false;
|
|
60
|
+
this.storeAsarChecked = false;
|
|
39
61
|
this.packageHelper.refCount++;
|
|
40
62
|
this.options =
|
|
41
63
|
targetName === "portable"
|
|
@@ -51,6 +73,14 @@ class NsisTarget extends core_1.Target {
|
|
|
51
73
|
if (deps != null && deps["electron-squirrel-startup"] != null) {
|
|
52
74
|
builder_util_1.log.warn('"electron-squirrel-startup" dependency is not required for NSIS');
|
|
53
75
|
}
|
|
76
|
+
if (this.options.useZip === true && !this.isZipPayload) {
|
|
77
|
+
if (this.isWebInstaller) {
|
|
78
|
+
builder_util_1.log.warn({ target: this.name, solution: "useZip only applies to the nsis and portable targets" }, "useZip is ignored because the web installer always uses a 7z package");
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
builder_util_1.log.warn({ target: this.name, solution: "set differentialPackage: false to get a zip payload" }, "useZip is ignored because differential-aware builds always use a 7z payload");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
54
84
|
}
|
|
55
85
|
get shouldBuildUniversalInstaller() {
|
|
56
86
|
const buildSeparateInstallers = this.options.buildUniversalInstaller === false;
|
|
@@ -66,32 +96,66 @@ class NsisTarget extends core_1.Target {
|
|
|
66
96
|
get isBuildDifferentialAware() {
|
|
67
97
|
return !this.isPortable && this.options.differentialPackage !== false;
|
|
68
98
|
}
|
|
99
|
+
// Single source of truth for the payload format: the archive written in buildAppPackage and the
|
|
100
|
+
// extractor selected by the ZIP_COMPRESSION / COMPRESSION_METHOD defines must never disagree.
|
|
101
|
+
// The web installer's download/extract path only handles 7z, so it never gets a zip package.
|
|
102
|
+
get isZipPayload() {
|
|
103
|
+
return !this.isWebInstaller && !this.isBuildDifferentialAware && this.options.useZip === true;
|
|
104
|
+
}
|
|
105
|
+
get isStoreAsar() {
|
|
106
|
+
return this.isBuildDifferentialAware && this.options.differentialPackage === "store-asar";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Everything that makes buildAppPackage's archive differ between targets. Targets sharing an
|
|
110
|
+
* AppPackageHelper (nsis + portable) reuse one app package per arch only when this key matches,
|
|
111
|
+
* so a target never embeds an archive whose format or layout was chosen by another target.
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
get appPackageCacheKey() {
|
|
115
|
+
const options = this.options;
|
|
116
|
+
return JSON.stringify({
|
|
117
|
+
format: this.isZipPayload ? "zip" : "7z",
|
|
118
|
+
differentialAware: this.isBuildDifferentialAware,
|
|
119
|
+
storeAsar: this.isStoreAsar,
|
|
120
|
+
excluded: this.getPreCompressedFileExtensions(),
|
|
121
|
+
// mirrors CopyElevateHelper's per-target packElevateHelper / perMachine resolution
|
|
122
|
+
elevate: options.packElevateHelper !== false || options.perMachine === true,
|
|
123
|
+
blockmap: this.isBuildDifferentialAware && this.isWebInstaller,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
69
126
|
getPreCompressedFileExtensions() {
|
|
70
127
|
const result = this.isWebInstaller ? null : this.options.preCompressedFileExtensions;
|
|
71
128
|
return result == null ? null : (0, builder_util_1.asArray)(result).map(it => (it.startsWith(".") ? it : `.${it}`));
|
|
72
129
|
}
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
130
|
+
/**
|
|
131
|
+
* @private
|
|
132
|
+
* @returns the package file info plus the absolute source paths of the members stored verbatim in it
|
|
133
|
+
* (`storedMemberFiles`, empty unless `differentialPackage` is `"store-asar"`).
|
|
134
|
+
*/
|
|
135
|
+
async buildAppPackage(appOutDir, arch, elevateHelper, fileNameSuffix = "") {
|
|
76
136
|
const packager = this.packager;
|
|
77
137
|
const isBuildDifferentialAware = this.isBuildDifferentialAware;
|
|
78
|
-
const format =
|
|
79
|
-
const archiveFile = path.join(this.outDir, `${packager.appInfo.sanitizedName}-${packager.appInfo.version}-${builder_util_1.Arch[arch]}.nsis.${format}`);
|
|
138
|
+
const format = this.isZipPayload ? "zip" : "7z";
|
|
139
|
+
const archiveFile = path.join(this.outDir, `${packager.appInfo.sanitizedName}-${packager.appInfo.version}-${builder_util_1.Arch[arch]}${fileNameSuffix}.nsis.${format}`);
|
|
80
140
|
const preCompressedFileExtensions = this.getPreCompressedFileExtensions();
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
141
|
+
const isStoreAsar = this.isStoreAsar;
|
|
142
|
+
if (isStoreAsar) {
|
|
143
|
+
await this.warnIfStoreAsarHasNoAsar(appOutDir);
|
|
144
|
+
}
|
|
145
|
+
// Opt-in via differentialPackage: "store-asar" — keep the asar a byte-stable Copy member so a
|
|
146
|
+
// differential update pays only for its changed blocks instead of re-downloading the whole
|
|
147
|
+
// recompressed asar (see nsisOptions docs). The blockmap chunks these verbatim bytes finer.
|
|
148
|
+
const storedPaths = isStoreAsar ? [exports.STORED_ASAR_PATH] : null;
|
|
149
|
+
// archive() skips a stored path that does not exist (e.g. `asar: false`, warned about above), so
|
|
150
|
+
// only the members that really end up in the package are located in it for the block map.
|
|
151
|
+
const storedMemberFiles = [];
|
|
152
|
+
for (const storedPath of storedPaths !== null && storedPaths !== void 0 ? storedPaths : []) {
|
|
153
|
+
const memberFile = path.join(appOutDir, storedPath);
|
|
154
|
+
if (await (0, builder_util_1.exists)(memberFile)) {
|
|
155
|
+
storedMemberFiles.push(memberFile);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const archiveOptions = createAppPackageArchiveOptions(packager.compression, preCompressedFileExtensions == null ? null : preCompressedFileExtensions.map(it => `*${it}`), storedPaths);
|
|
95
159
|
const timer = (0, timer_1.time)(`nsis package, ${builder_util_1.Arch[arch]}`);
|
|
96
160
|
await (0, archive_1.archive)(format, archiveFile, appOutDir, isBuildDifferentialAware ? (0, differentialUpdateInfoBuilder_1.configureDifferentialAwareArchiveOptions)(archiveOptions) : archiveOptions);
|
|
97
161
|
timer.end();
|
|
@@ -104,15 +168,38 @@ class NsisTarget extends core_1.Target {
|
|
|
104
168
|
await elevateHelper.addToArchive(archiveFile, this, format, archiveOptions, appOutDir);
|
|
105
169
|
}
|
|
106
170
|
if (isBuildDifferentialAware && this.isWebInstaller) {
|
|
107
|
-
const
|
|
171
|
+
const regions = await (0, differentialUpdateInfoBuilder_1.locateStoredMemberRegions)(archiveFile, storedMemberFiles);
|
|
172
|
+
const data = await (0, differentialUpdateInfoBuilder_1.appendBlockmap)(archiveFile, (0, differentialUpdateInfoBuilder_1.toBlockMapOptions)(regions));
|
|
108
173
|
return {
|
|
109
|
-
|
|
110
|
-
|
|
174
|
+
fileInfo: {
|
|
175
|
+
...data,
|
|
176
|
+
path: archiveFile,
|
|
177
|
+
},
|
|
178
|
+
storedMemberFiles,
|
|
111
179
|
};
|
|
112
180
|
}
|
|
113
181
|
else {
|
|
114
|
-
return await createPackageFileInfo(archiveFile);
|
|
182
|
+
return { fileInfo: await createPackageFileInfo(archiveFile), storedMemberFiles };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* `archive()` silently skips stored paths that don't exist, so without an asar (e.g. `asar: false`)
|
|
187
|
+
* "store-asar" would do nothing unnoticed. The fallback is harmless — the differential package is
|
|
188
|
+
* non-solid, so each unpacked file is already its own block — but say so once per target.
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
async warnIfStoreAsarHasNoAsar(appOutDir) {
|
|
192
|
+
// every arch is packaged with the same asar setting, so checking the first one is enough (and
|
|
193
|
+
// flagging before the await keeps concurrent per-arch packaging from warning twice)
|
|
194
|
+
if (this.storeAsarChecked) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.storeAsarChecked = true;
|
|
198
|
+
const asarFile = path.join(appOutDir, exports.STORED_ASAR_PATH);
|
|
199
|
+
if (await (0, builder_util_1.exists)(asarFile)) {
|
|
200
|
+
return;
|
|
115
201
|
}
|
|
202
|
+
builder_util_1.log.warn({ reason: `${exports.STORED_ASAR_PATH} not found (e.g. asar is disabled)`, file: builder_util_1.log.filePath(asarFile) }, 'differentialPackage "store-asar" has no effect, the app package is compressed normally');
|
|
116
203
|
}
|
|
117
204
|
installerFilenamePattern(primaryArch, defaultArch) {
|
|
118
205
|
const setupText = this.isPortable ? "" : "Setup ";
|
|
@@ -216,6 +303,8 @@ class NsisTarget extends core_1.Target {
|
|
|
216
303
|
}
|
|
217
304
|
}
|
|
218
305
|
const packageFiles = {};
|
|
306
|
+
// stored (Copy) members of every arch package, to be located in the installer for its block map
|
|
307
|
+
const storedMemberFiles = [];
|
|
219
308
|
let estimatedSize = 0;
|
|
220
309
|
if (this.isPortable && options.useZip) {
|
|
221
310
|
for (const [arch, dir] of archs.entries()) {
|
|
@@ -228,7 +317,8 @@ class NsisTarget extends core_1.Target {
|
|
|
228
317
|
}
|
|
229
318
|
else {
|
|
230
319
|
await Promise.all(Array.from(archs.keys()).map(async (arch) => {
|
|
231
|
-
const { fileInfo, unpackedSize } = await this.packageHelper.packArch(arch, this);
|
|
320
|
+
const { fileInfo, unpackedSize, storedMemberFiles: archStoredMemberFiles } = await this.packageHelper.packArch(arch, this);
|
|
321
|
+
storedMemberFiles.push(...archStoredMemberFiles);
|
|
232
322
|
const file = fileInfo.path;
|
|
233
323
|
const defineKey = arch === builder_util_1.Arch.x64 ? "APP_64" : arch === builder_util_1.Arch.arm64 ? "APP_ARM64" : "APP_32";
|
|
234
324
|
defines[defineKey] = file;
|
|
@@ -323,7 +413,10 @@ class NsisTarget extends core_1.Target {
|
|
|
323
413
|
updateInfo = (0, differentialUpdateInfoBuilder_1.createNsisWebDifferentialUpdateInfo)(installerPath, packageFiles);
|
|
324
414
|
}
|
|
325
415
|
else if (this.isBuildDifferentialAware) {
|
|
326
|
-
|
|
416
|
+
// Every arch package is embedded verbatim in the installer (SetCompress off), so the stored
|
|
417
|
+
// members of all of them sit verbatim in the signed installer too; locate them there.
|
|
418
|
+
const regions = await (0, differentialUpdateInfoBuilder_1.locateStoredMemberRegions)(installerPath, storedMemberFiles);
|
|
419
|
+
updateInfo = await (0, differentialUpdateInfoBuilder_1.createBlockmap)(installerPath, this, packager, safeArtifactName, (0, differentialUpdateInfoBuilder_1.toBlockMapOptions)(regions));
|
|
327
420
|
}
|
|
328
421
|
if (updateInfo != null && isPerMachine && (oneClick || options.packElevateHelper)) {
|
|
329
422
|
updateInfo.isAdminRightsRequired = true;
|
|
@@ -519,11 +612,10 @@ class NsisTarget extends core_1.Target {
|
|
|
519
612
|
defines.APP_INSTALLER_STORE_FILE = `${appInfo.updaterCacheDirName}\\${builder_util_runtime_1.CURRENT_APP_INSTALLER_FILE_NAME}`;
|
|
520
613
|
}
|
|
521
614
|
if (!this.isWebInstaller && defines.APP_BUILD_DIR == null) {
|
|
522
|
-
|
|
523
|
-
if (options.useZip) {
|
|
615
|
+
if (this.isZipPayload) {
|
|
524
616
|
defines.ZIP_COMPRESSION = null;
|
|
525
617
|
}
|
|
526
|
-
defines.COMPRESSION_METHOD =
|
|
618
|
+
defines.COMPRESSION_METHOD = this.isZipPayload ? "zip" : "7z";
|
|
527
619
|
}
|
|
528
620
|
}
|
|
529
621
|
async executeMakensis(defines, commands, script, opts = {}) {
|