app-builder-lib 27.0.0-alpha.10 → 27.0.0-alpha.11

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.
Files changed (157) hide show
  1. package/dist/asar/asarAlign.d.ts +35 -0
  2. package/dist/asar/asarAlign.d.ts.map +1 -0
  3. package/dist/asar/asarAlign.js +149 -0
  4. package/dist/asar/asarAlign.js.map +1 -0
  5. package/dist/asar/asarUtil.d.ts +15 -1
  6. package/dist/asar/asarUtil.d.ts.map +1 -1
  7. package/dist/asar/asarUtil.js +111 -61
  8. package/dist/asar/asarUtil.js.map +1 -1
  9. package/dist/configuration.d.ts +5 -3
  10. package/dist/configuration.d.ts.map +1 -1
  11. package/dist/configuration.js.map +1 -1
  12. package/dist/fileMatcher.d.ts +13 -1
  13. package/dist/fileMatcher.d.ts.map +1 -1
  14. package/dist/fileMatcher.js +29 -11
  15. package/dist/fileMatcher.js.map +1 -1
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/indexInternal.d.ts +3 -2
  20. package/dist/indexInternal.d.ts.map +1 -1
  21. package/dist/indexInternal.js +3 -2
  22. package/dist/indexInternal.js.map +1 -1
  23. package/dist/options/PlatformSpecificBuildOptions.d.ts +92 -3
  24. package/dist/options/PlatformSpecificBuildOptions.d.ts.map +1 -1
  25. package/dist/options/PlatformSpecificBuildOptions.js.map +1 -1
  26. package/dist/options/SnapOptions.d.ts +36 -15
  27. package/dist/options/SnapOptions.d.ts.map +1 -1
  28. package/dist/options/SnapOptions.js.map +1 -1
  29. package/dist/options/linuxOptions.d.ts +53 -18
  30. package/dist/options/linuxOptions.d.ts.map +1 -1
  31. package/dist/options/linuxOptions.js.map +1 -1
  32. package/dist/packager.d.ts.map +1 -1
  33. package/dist/packager.js +2 -0
  34. package/dist/packager.js.map +1 -1
  35. package/dist/platformPackager.d.ts +7 -2
  36. package/dist/platformPackager.d.ts.map +1 -1
  37. package/dist/platformPackager.js +41 -16
  38. package/dist/platformPackager.js.map +1 -1
  39. package/dist/presets/rectCra.js +3 -1
  40. package/dist/presets/rectCra.js.map +1 -1
  41. package/dist/publish/PublishManager.d.ts +5 -1
  42. package/dist/publish/PublishManager.d.ts.map +1 -1
  43. package/dist/publish/PublishManager.js +22 -44
  44. package/dist/publish/PublishManager.js.map +1 -1
  45. package/dist/publish/updateInfoBuilder.d.ts.map +1 -1
  46. package/dist/publish/updateInfoBuilder.js +8 -10
  47. package/dist/publish/updateInfoBuilder.js.map +1 -1
  48. package/dist/targets/ArchiveTarget.d.ts.map +1 -1
  49. package/dist/targets/ArchiveTarget.js +7 -1
  50. package/dist/targets/ArchiveTarget.js.map +1 -1
  51. package/dist/targets/archive.d.ts +6 -0
  52. package/dist/targets/archive.d.ts.map +1 -1
  53. package/dist/targets/archive.js +5 -1
  54. package/dist/targets/archive.js.map +1 -1
  55. package/dist/targets/blockmap/blockmap.d.ts +3 -2
  56. package/dist/targets/blockmap/blockmap.d.ts.map +1 -1
  57. package/dist/targets/blockmap/blockmap.js +3 -2
  58. package/dist/targets/blockmap/blockmap.js.map +1 -1
  59. package/dist/targets/linux/FlatpakTarget.d.ts +17 -0
  60. package/dist/targets/linux/FlatpakTarget.d.ts.map +1 -1
  61. package/dist/targets/linux/FlatpakTarget.js +238 -48
  62. package/dist/targets/linux/FlatpakTarget.js.map +1 -1
  63. package/dist/targets/linux/FpmTarget.d.ts.map +1 -1
  64. package/dist/targets/linux/FpmTarget.js +8 -4
  65. package/dist/targets/linux/FpmTarget.js.map +1 -1
  66. package/dist/targets/linux/LinuxTargetHelper.d.ts +1 -3
  67. package/dist/targets/linux/LinuxTargetHelper.d.ts.map +1 -1
  68. package/dist/targets/linux/LinuxTargetHelper.js +45 -20
  69. package/dist/targets/linux/LinuxTargetHelper.js.map +1 -1
  70. package/dist/targets/linux/appimage/AppImageTarget.d.ts.map +1 -1
  71. package/dist/targets/linux/appimage/AppImageTarget.js +5 -1
  72. package/dist/targets/linux/appimage/AppImageTarget.js.map +1 -1
  73. package/dist/targets/linux/appimage/appImageUtil.d.ts +3 -1
  74. package/dist/targets/linux/appimage/appImageUtil.d.ts.map +1 -1
  75. package/dist/targets/linux/appimage/appImageUtil.js +2 -2
  76. package/dist/targets/linux/appimage/appImageUtil.js.map +1 -1
  77. package/dist/targets/linux/appimage/appLauncher.d.ts +6 -0
  78. package/dist/targets/linux/appimage/appLauncher.d.ts.map +1 -1
  79. package/dist/targets/linux/appimage/appLauncher.js +13 -9
  80. package/dist/targets/linux/appimage/appLauncher.js.map +1 -1
  81. package/dist/targets/linux/flatpakBundle.d.ts +43 -0
  82. package/dist/targets/linux/flatpakBundle.d.ts.map +1 -0
  83. package/dist/targets/linux/flatpakBundle.js +210 -0
  84. package/dist/targets/linux/flatpakBundle.js.map +1 -0
  85. package/dist/targets/linux/snap/core24.d.ts +0 -18
  86. package/dist/targets/linux/snap/core24.d.ts.map +1 -1
  87. package/dist/targets/linux/snap/core24.js +27 -91
  88. package/dist/targets/linux/snap/core24.js.map +1 -1
  89. package/dist/targets/linux/snap/coreLegacy.d.ts +7 -0
  90. package/dist/targets/linux/snap/coreLegacy.d.ts.map +1 -1
  91. package/dist/targets/linux/snap/coreLegacy.js +25 -6
  92. package/dist/targets/linux/snap/coreLegacy.js.map +1 -1
  93. package/dist/targets/linux/snap/snapPlugs.d.ts +76 -0
  94. package/dist/targets/linux/snap/snapPlugs.d.ts.map +1 -0
  95. package/dist/targets/linux/snap/snapPlugs.js +242 -0
  96. package/dist/targets/linux/snap/snapPlugs.js.map +1 -0
  97. package/dist/targets/win/nsis/Defines.d.ts +1 -0
  98. package/dist/targets/win/nsis/Defines.d.ts.map +1 -1
  99. package/dist/targets/win/nsis/Defines.js.map +1 -1
  100. package/dist/targets/win/nsis/NsisTarget.d.ts +8 -1
  101. package/dist/targets/win/nsis/NsisTarget.d.ts.map +1 -1
  102. package/dist/targets/win/nsis/NsisTarget.js +29 -4
  103. package/dist/targets/win/nsis/NsisTarget.js.map +1 -1
  104. package/dist/targets/win/nsis/nsisOptions.d.ts +6 -4
  105. package/dist/targets/win/nsis/nsisOptions.d.ts.map +1 -1
  106. package/dist/targets/win/nsis/nsisOptions.js.map +1 -1
  107. package/dist/targets/win/nsis/nsisUtil.d.ts.map +1 -1
  108. package/dist/targets/win/nsis/nsisUtil.js +7 -2
  109. package/dist/targets/win/nsis/nsisUtil.js.map +1 -1
  110. package/dist/targets/win/winAppUtil.d.ts +2 -2
  111. package/dist/targets/win/winAppUtil.d.ts.map +1 -1
  112. package/dist/targets/win/winAppUtil.js +5 -3
  113. package/dist/targets/win/winAppUtil.js.map +1 -1
  114. package/dist/toolsets/appimage.d.ts.map +1 -1
  115. package/dist/toolsets/appimage.js +19 -19
  116. package/dist/toolsets/appimage.js.map +1 -1
  117. package/dist/toolsets/nsis.js +1 -1
  118. package/dist/toolsets/nsis.js.map +1 -1
  119. package/dist/util/AppFileWalker.js +9 -1
  120. package/dist/util/AppFileWalker.js.map +1 -1
  121. package/dist/util/appFileCopier.d.ts +15 -2
  122. package/dist/util/appFileCopier.d.ts.map +1 -1
  123. package/dist/util/appFileCopier.js +24 -12
  124. package/dist/util/appFileCopier.js.map +1 -1
  125. package/dist/util/config/config.d.ts +1 -1
  126. package/dist/util/config/config.d.ts.map +1 -1
  127. package/dist/util/config/config.js +34 -19
  128. package/dist/util/config/config.js.map +1 -1
  129. package/dist/util/config/fileOptions.d.ts +30 -0
  130. package/dist/util/config/fileOptions.d.ts.map +1 -0
  131. package/dist/util/config/fileOptions.js +120 -0
  132. package/dist/util/config/fileOptions.js.map +1 -0
  133. package/dist/util/config/legacyConfigGuard.d.ts.map +1 -1
  134. package/dist/util/config/legacyConfigGuard.js +31 -4
  135. package/dist/util/config/legacyConfigGuard.js.map +1 -1
  136. package/dist/util/config/legacyOptions.d.ts +11 -0
  137. package/dist/util/config/legacyOptions.d.ts.map +1 -1
  138. package/dist/util/config/legacyOptions.js +24 -10
  139. package/dist/util/config/legacyOptions.js.map +1 -1
  140. package/dist/util/electronGet.d.ts +13 -0
  141. package/dist/util/electronGet.d.ts.map +1 -1
  142. package/dist/util/electronGet.js +40 -17
  143. package/dist/util/electronGet.js.map +1 -1
  144. package/dist/util/removedEnvVars.d.ts +25 -0
  145. package/dist/util/removedEnvVars.d.ts.map +1 -0
  146. package/dist/util/removedEnvVars.js +54 -0
  147. package/dist/util/removedEnvVars.js.map +1 -0
  148. package/dist/util/trustedSourceRoots.d.ts +59 -0
  149. package/dist/util/trustedSourceRoots.d.ts.map +1 -0
  150. package/dist/util/trustedSourceRoots.js +127 -0
  151. package/dist/util/trustedSourceRoots.js.map +1 -0
  152. package/dist/version.d.ts +1 -1
  153. package/dist/version.js +1 -1
  154. package/dist/version.js.map +1 -1
  155. package/package.json +15 -16
  156. package/scheme.json +266 -419
  157. package/templates/nsis/include/installer.nsh +11 -8
@@ -0,0 +1,35 @@
1
+ export interface AsarAlignmentResult {
2
+ /** packed files whose content was re-laid */
3
+ files: number;
4
+ /** total zero padding between files in the resulting layout */
5
+ paddingBytes: number;
6
+ /** archive size before / after */
7
+ sizeBefore: number;
8
+ sizeAfter: number;
9
+ }
10
+ /** Above this alignment every file is padded up to a boundary that is likely much larger than the file itself. */
11
+ export declare const CONTENT_ALIGNMENT_WARN_THRESHOLD: number;
12
+ /**
13
+ * Validates an `asar.contentAlignment` value. Called from `computeAsarOptions` before packing starts and
14
+ * again by `alignAsarContent` (which is public and used directly by the benchmark).
15
+ */
16
+ export declare function validateContentAlignment(alignment: unknown): asserts alignment is number;
17
+ /**
18
+ * Re-lays the content region of an existing asar so that every packed file's content starts at a
19
+ * multiple of `alignment` bytes (zero padding between files; file order, sizes and per-file
20
+ * `integrity` are untouched — only the header's `offset` strings change). Readers locate content by
21
+ * `offset` + `size`, so gaps between files are transparent to Electron and `@electron/asar`.
22
+ *
23
+ * Why: the differential updater diffs the stored `app.asar` block-wise, and the asar header stores
24
+ * every file's absolute content offset. Without alignment a change that grows a file by even one
25
+ * byte shifts the offset of every later file, rewriting most of the header — with alignment a file
26
+ * can grow within its slot and no other offset moves.
27
+ *
28
+ * Streams the archive (peak memory ≈ header + 1 MiB, whatever the alignment: padding is written from
29
+ * one shared zero buffer), writes `<file>.aligning`, verifies its size against the computed layout, closes
30
+ * both handles and renames it over the original; on any failure the original is untouched and the temp
31
+ * file removed.
32
+ * Idempotent: an already aligned archive is rewritten byte-identically.
33
+ */
34
+ export declare function alignAsarContent(asarFile: string, alignment: number): Promise<AsarAlignmentResult>;
35
+ //# sourceMappingURL=asarAlign.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asarAlign.d.ts","sourceRoot":"","sources":["../../src/asar/asarAlign.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAA;IACb,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAA;IACpB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;CAClB;AAID,kHAAkH;AAClH,eAAO,MAAM,gCAAgC,QAAY,CAAA;AAEzD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAIxF;AAwDD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA0ExG"}
@@ -0,0 +1,149 @@
1
+ import { InvalidConfigurationError, log } from "builder-util";
2
+ import chromiumPickleJs from "chromium-pickle-js";
3
+ import fs from "fs-extra";
4
+ import { readAsarHeader } from "./asar.js";
5
+ const COPY_CHUNK = 1024 * 1024;
6
+ /** Above this alignment every file is padded up to a boundary that is likely much larger than the file itself. */
7
+ export const CONTENT_ALIGNMENT_WARN_THRESHOLD = 64 * 1024;
8
+ /**
9
+ * Validates an `asar.contentAlignment` value. Called from `computeAsarOptions` before packing starts and
10
+ * again by `alignAsarContent` (which is public and used directly by the benchmark).
11
+ */
12
+ export function validateContentAlignment(alignment) {
13
+ if (typeof alignment !== "number" || !Number.isInteger(alignment) || alignment < 1) {
14
+ throw new InvalidConfigurationError(`asar.contentAlignment must be a positive integer, got ${String(alignment)}`);
15
+ }
16
+ }
17
+ function collectPackedFiles(node, result) {
18
+ const files = node.files;
19
+ if (files == null) {
20
+ return;
21
+ }
22
+ for (const child of Object.values(files)) {
23
+ if (child.files != null) {
24
+ collectPackedFiles(child, result);
25
+ }
26
+ else if (child.offset != null && !child.unpacked && child.link == null) {
27
+ result.push({ node: child, offset: parseInt(child.offset, 10), size: child.size ?? 0 });
28
+ }
29
+ }
30
+ }
31
+ function serializeHeader(headerJson) {
32
+ const headerPickle = chromiumPickleJs.createEmpty();
33
+ headerPickle.writeString(headerJson);
34
+ const headerBuf = headerPickle.toBuffer();
35
+ const sizePickle = chromiumPickleJs.createEmpty();
36
+ sizePickle.writeUInt32(headerBuf.length);
37
+ return Buffer.concat([sizePickle.toBuffer(), headerBuf]);
38
+ }
39
+ /** `fs.write` may write fewer bytes than asked; loop until the whole range is on disk. */
40
+ async function writeFully(fd, buffer, length) {
41
+ let done = 0;
42
+ while (done < length) {
43
+ const { bytesWritten } = await fs.write(fd, buffer, done, length - done);
44
+ if (bytesWritten <= 0) {
45
+ throw new Error(`short write while aligning asar content: ${done} of ${length} bytes written`);
46
+ }
47
+ done += bytesWritten;
48
+ }
49
+ }
50
+ async function copyRange(inFd, outFd, start, size, buffer) {
51
+ let copied = 0;
52
+ while (copied < size) {
53
+ const n = Math.min(buffer.length, size - copied);
54
+ const { bytesRead } = await fs.read(inFd, buffer, 0, n, start + copied);
55
+ if (bytesRead !== n) {
56
+ throw new Error(`Unexpected end of asar content: wanted ${n} bytes at ${start + copied}, got ${bytesRead}`);
57
+ }
58
+ await writeFully(outFd, buffer, n);
59
+ copied += n;
60
+ }
61
+ }
62
+ /**
63
+ * Re-lays the content region of an existing asar so that every packed file's content starts at a
64
+ * multiple of `alignment` bytes (zero padding between files; file order, sizes and per-file
65
+ * `integrity` are untouched — only the header's `offset` strings change). Readers locate content by
66
+ * `offset` + `size`, so gaps between files are transparent to Electron and `@electron/asar`.
67
+ *
68
+ * Why: the differential updater diffs the stored `app.asar` block-wise, and the asar header stores
69
+ * every file's absolute content offset. Without alignment a change that grows a file by even one
70
+ * byte shifts the offset of every later file, rewriting most of the header — with alignment a file
71
+ * can grow within its slot and no other offset moves.
72
+ *
73
+ * Streams the archive (peak memory ≈ header + 1 MiB, whatever the alignment: padding is written from
74
+ * one shared zero buffer), writes `<file>.aligning`, verifies its size against the computed layout, closes
75
+ * both handles and renames it over the original; on any failure the original is untouched and the temp
76
+ * file removed.
77
+ * Idempotent: an already aligned archive is rewritten byte-identically.
78
+ */
79
+ export async function alignAsarContent(asarFile, alignment) {
80
+ validateContentAlignment(alignment);
81
+ const { header: headerJson, size: headerSize } = await readAsarHeader(asarFile);
82
+ const header = JSON.parse(headerJson);
83
+ const contentStart = 8 + headerSize;
84
+ const sizeBefore = (await fs.stat(asarFile)).size;
85
+ const files = [];
86
+ collectPackedFiles(header, files);
87
+ files.sort((a, b) => a.offset - b.offset);
88
+ let cursor = 0;
89
+ let paddingBytes = 0;
90
+ const layout = files.map(file => {
91
+ const aligned = Math.ceil(cursor / alignment) * alignment;
92
+ paddingBytes += aligned - cursor;
93
+ file.node.offset = String(aligned);
94
+ cursor = aligned + file.size;
95
+ return { ...file, newOffset: aligned };
96
+ });
97
+ const newHeader = serializeHeader(JSON.stringify(header));
98
+ const expectedSize = newHeader.length + cursor;
99
+ const tempFile = `${asarFile}.aligning`;
100
+ let inFd = await fs.open(asarFile, "r");
101
+ let outFd = null;
102
+ try {
103
+ outFd = await fs.open(tempFile, "w");
104
+ await writeFully(outFd, newHeader, newHeader.length);
105
+ const buffer = Buffer.allocUnsafe(COPY_CHUNK);
106
+ const zeros = Buffer.alloc(Math.min(alignment, COPY_CHUNK));
107
+ let written = 0;
108
+ for (const file of layout) {
109
+ for (let gap = file.newOffset - written; gap > 0;) {
110
+ const n = Math.min(gap, zeros.length);
111
+ await writeFully(outFd, zeros, n);
112
+ gap -= n;
113
+ written += n;
114
+ }
115
+ await copyRange(inFd, outFd, contentStart + file.offset, file.size, buffer);
116
+ written += file.size;
117
+ }
118
+ const { size: actualSize } = await fs.fstat(outFd);
119
+ if (written !== cursor || actualSize !== expectedSize) {
120
+ throw new Error(`aligned asar is ${actualSize} bytes (${written} content bytes written), expected ${expectedSize} (${cursor} content bytes)`);
121
+ }
122
+ await fs.close(outFd);
123
+ outFd = null;
124
+ // Windows refuses to replace a file that still has an open handle (EPERM): close the source before the rename
125
+ await fs.close(inFd);
126
+ inFd = null;
127
+ await fs.rename(tempFile, asarFile);
128
+ }
129
+ catch (e) {
130
+ if (outFd != null) {
131
+ await fs.close(outFd).catch(() => undefined);
132
+ outFd = null;
133
+ }
134
+ await fs.remove(tempFile).catch(() => undefined);
135
+ throw e;
136
+ }
137
+ finally {
138
+ if (inFd != null) {
139
+ await fs.close(inFd);
140
+ }
141
+ if (outFd != null) {
142
+ await fs.close(outFd);
143
+ }
144
+ }
145
+ const sizeAfter = (await fs.stat(asarFile)).size;
146
+ log.info({ file: log.filePath(asarFile), alignment, files: files.length, padding: paddingBytes, size: `${sizeBefore} → ${sizeAfter}` }, "aligned asar content");
147
+ return { files: files.length, paddingBytes, sizeBefore, sizeAfter };
148
+ }
149
+ //# sourceMappingURL=asarAlign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asarAlign.js","sourceRoot":"","sources":["../../src/asar/asarAlign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,EAAQ,cAAc,EAAE,MAAM,WAAW,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,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACvB,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA;IAChD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,UAAU,MAAM,SAAS,EAAE,EAAE,EAAE,sBAAsB,CAAC,CAAA;IAC/J,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA;AACrE,CAAC","sourcesContent":["import { InvalidConfigurationError, log } from \"builder-util\"\nimport chromiumPickleJs from \"chromium-pickle-js\"\nimport fs from \"fs-extra\"\nimport { Node, readAsarHeader } from \"./asar.js\"\n\nexport interface AsarAlignmentResult {\n /** packed files whose content was re-laid */\n files: number\n /** total zero padding between files in the resulting layout */\n paddingBytes: number\n /** archive size before / after */\n sizeBefore: number\n sizeAfter: number\n}\n\nconst COPY_CHUNK = 1024 * 1024\n\n/** Above this alignment every file is padded up to a boundary that is likely much larger than the file itself. */\nexport const CONTENT_ALIGNMENT_WARN_THRESHOLD = 64 * 1024\n\n/**\n * Validates an `asar.contentAlignment` value. Called from `computeAsarOptions` before packing starts and\n * again by `alignAsarContent` (which is public and used directly by the benchmark).\n */\nexport function validateContentAlignment(alignment: unknown): asserts alignment is number {\n if (typeof alignment !== \"number\" || !Number.isInteger(alignment) || alignment < 1) {\n throw new InvalidConfigurationError(`asar.contentAlignment must be a positive integer, got ${String(alignment)}`)\n }\n}\n\ninterface PackedFile {\n node: Node\n offset: number\n size: number\n}\n\nfunction collectPackedFiles(node: Node, result: Array<PackedFile>): void {\n const files = node.files\n if (files == null) {\n return\n }\n for (const child of Object.values(files)) {\n if (child.files != null) {\n collectPackedFiles(child, result)\n } else if (child.offset != null && !child.unpacked && child.link == null) {\n result.push({ node: child, offset: parseInt(child.offset, 10), size: child.size ?? 0 })\n }\n }\n}\n\nfunction serializeHeader(headerJson: string): Buffer {\n const headerPickle = chromiumPickleJs.createEmpty()\n headerPickle.writeString(headerJson)\n const headerBuf: Buffer = headerPickle.toBuffer()\n const sizePickle = chromiumPickleJs.createEmpty()\n sizePickle.writeUInt32(headerBuf.length)\n return Buffer.concat([sizePickle.toBuffer(), headerBuf])\n}\n\n/** `fs.write` may write fewer bytes than asked; loop until the whole range is on disk. */\nasync function writeFully(fd: number, buffer: Buffer, length: number): Promise<void> {\n let done = 0\n while (done < length) {\n const { bytesWritten } = await fs.write(fd, buffer, done, length - done)\n if (bytesWritten <= 0) {\n throw new Error(`short write while aligning asar content: ${done} of ${length} bytes written`)\n }\n done += bytesWritten\n }\n}\n\nasync function copyRange(inFd: number, outFd: number, start: number, size: number, buffer: Buffer): Promise<void> {\n let copied = 0\n while (copied < size) {\n const n = Math.min(buffer.length, size - copied)\n const { bytesRead } = await fs.read(inFd, buffer, 0, n, start + copied)\n if (bytesRead !== n) {\n throw new Error(`Unexpected end of asar content: wanted ${n} bytes at ${start + copied}, got ${bytesRead}`)\n }\n await writeFully(outFd, buffer, n)\n copied += n\n }\n}\n\n/**\n * Re-lays the content region of an existing asar so that every packed file's content starts at a\n * multiple of `alignment` bytes (zero padding between files; file order, sizes and per-file\n * `integrity` are untouched — only the header's `offset` strings change). Readers locate content by\n * `offset` + `size`, so gaps between files are transparent to Electron and `@electron/asar`.\n *\n * Why: the differential updater diffs the stored `app.asar` block-wise, and the asar header stores\n * every file's absolute content offset. Without alignment a change that grows a file by even one\n * byte shifts the offset of every later file, rewriting most of the header — with alignment a file\n * can grow within its slot and no other offset moves.\n *\n * Streams the archive (peak memory ≈ header + 1 MiB, whatever the alignment: padding is written from\n * one shared zero buffer), writes `<file>.aligning`, verifies its size against the computed layout, closes\n * both handles and renames it over the original; on any failure the original is untouched and the temp\n * file removed.\n * Idempotent: an already aligned archive is rewritten byte-identically.\n */\nexport async function alignAsarContent(asarFile: string, alignment: number): Promise<AsarAlignmentResult> {\n validateContentAlignment(alignment)\n\n const { header: headerJson, size: headerSize } = await readAsarHeader(asarFile)\n const header = JSON.parse(headerJson) as Node\n const contentStart = 8 + headerSize\n const sizeBefore = (await fs.stat(asarFile)).size\n\n const files: Array<PackedFile> = []\n collectPackedFiles(header, files)\n files.sort((a, b) => a.offset - b.offset)\n\n let cursor = 0\n let paddingBytes = 0\n const layout = files.map(file => {\n const aligned = Math.ceil(cursor / alignment) * alignment\n paddingBytes += aligned - cursor\n file.node.offset = String(aligned)\n cursor = aligned + file.size\n return { ...file, newOffset: aligned }\n })\n\n const newHeader = serializeHeader(JSON.stringify(header))\n const expectedSize = newHeader.length + cursor\n\n const tempFile = `${asarFile}.aligning`\n let inFd: number | null = await fs.open(asarFile, \"r\")\n let outFd: number | null = null\n try {\n outFd = await fs.open(tempFile, \"w\")\n await writeFully(outFd, newHeader, newHeader.length)\n const buffer = Buffer.allocUnsafe(COPY_CHUNK)\n const zeros = Buffer.alloc(Math.min(alignment, COPY_CHUNK))\n let written = 0\n for (const file of layout) {\n for (let gap = file.newOffset - written; gap > 0;) {\n const n = Math.min(gap, zeros.length)\n await writeFully(outFd, zeros, n)\n gap -= n\n written += n\n }\n await copyRange(inFd, outFd, contentStart + file.offset, file.size, buffer)\n written += file.size\n }\n\n const { size: actualSize } = await fs.fstat(outFd)\n if (written !== cursor || actualSize !== expectedSize) {\n throw new Error(`aligned asar is ${actualSize} bytes (${written} content bytes written), expected ${expectedSize} (${cursor} content bytes)`)\n }\n await fs.close(outFd)\n outFd = null\n // Windows refuses to replace a file that still has an open handle (EPERM): close the source before the rename\n await fs.close(inFd)\n inFd = null\n await fs.rename(tempFile, asarFile)\n } catch (e) {\n if (outFd != null) {\n await fs.close(outFd).catch(() => undefined)\n outFd = null\n }\n await fs.remove(tempFile).catch(() => undefined)\n throw e\n } finally {\n if (inFd != null) {\n await fs.close(inFd)\n }\n if (outFd != null) {\n await fs.close(outFd)\n }\n }\n\n const sizeAfter = (await fs.stat(asarFile)).size\n log.info({ file: log.filePath(asarFile), alignment, files: files.length, padding: paddingBytes, size: `${sizeBefore} → ${sizeAfter}` }, \"aligned asar content\")\n return { files: files.length, paddingBytes, sizeBefore, sizeAfter }\n}\n"]}
@@ -1,2 +1,16 @@
1
- export {};
1
+ import type { AsarStreamType } from "@electron/asar";
2
+ /**
3
+ * Applies an asar ordering file (`asar.ordering`) to the stream list `@electron/asar` packs: directory entries move to
4
+ * the front in their original relative order (they hold no data), the listed files follow in the order of the file,
5
+ * then everything else in its original order. Lines use the same syntax `@electron/asar` accepts — a path relative to
6
+ * the app root, optionally prefixed with `/` or with a `<anything>:` prefix (e.g. a load counter) — blank lines are
7
+ * ignored and `\` separators are accepted. Lines naming a directory are ignored; files listed but not present are
8
+ * counted in `listed`, reported in `missing` and skipped.
9
+ */
10
+ export declare function orderAsarStreams(streams: Array<AsarStreamType>, orderingLines: Array<string>): {
11
+ streams: Array<AsarStreamType>;
12
+ listed: number;
13
+ matched: number;
14
+ missing: Array<string>;
15
+ };
2
16
  //# sourceMappingURL=asarUtil.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asarUtil.d.ts","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"asarUtil.d.ts","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAiB,MAAM,gBAAgB,CAAA;AAoBnE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,EAC9B,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,GAC3B;IAAE,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CA8C7F"}
@@ -1,36 +1,109 @@
1
- import { exists, isEmptyOrSpaces, log } from "builder-util";
1
+ import { InvalidConfigurationError, isEmptyOrSpaces, log } from "builder-util";
2
2
  import { dynamicImport } from "../util/dynamicImport.js";
3
3
  import fs from "fs-extra";
4
4
  import * as path from "path";
5
5
  import { getDestinationPath } from "../util/appFileCopier.js";
6
6
  import { detectUnpackedDirs } from "./unpackDetector.js";
7
+ import { alignAsarContent } from "./asarAlign.js";
8
+ import { assertSourceFileInTrustedRoots, getTrustedSourceRoots } from "../util/trustedSourceRoots.js";
7
9
  import { Readable } from "stream";
8
- import * as os from "os";
9
10
  const { readlink } = fs;
10
- const resolvePath = async (file) => (file && (await exists(file)) ? fs.realpath(file).catch(() => path.resolve(file)) : undefined);
11
- const resolvePaths = async (filepaths) => {
12
- return Promise.all(filepaths.map(resolvePath)).then(paths => paths.filter((it) => it != null));
13
- };
14
- const DENYLIST = resolvePaths([
15
- "/usr",
16
- "/lib",
17
- "/bin",
18
- "/sbin",
19
- "/etc",
20
- "/tmp",
21
- "/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
22
- // macOS system directories
23
- "/System",
24
- "/Library",
25
- "/private",
26
- // Windows system directories
27
- process.env.SystemRoot,
28
- process.env.WINDIR,
29
- ]);
30
- const ALLOWLIST = resolvePaths([
31
- os.tmpdir(), // always allow temp dir
32
- os.homedir(), // always allow home dir
33
- ]);
11
+ /** @internal */
12
+ export function isPathInside(root, target) {
13
+ return target === root || target.startsWith(root + path.sep);
14
+ }
15
+ /**
16
+ * Applies an asar ordering file (`asar.ordering`) to the stream list `@electron/asar` packs: directory entries move to
17
+ * the front in their original relative order (they hold no data), the listed files follow in the order of the file,
18
+ * then everything else in its original order. Lines use the same syntax `@electron/asar` accepts — a path relative to
19
+ * the app root, optionally prefixed with `/` or with a `<anything>:` prefix (e.g. a load counter) — blank lines are
20
+ * ignored and `\` separators are accepted. Lines naming a directory are ignored; files listed but not present are
21
+ * counted in `listed`, reported in `missing` and skipped.
22
+ */
23
+ export function orderAsarStreams(streams, orderingLines) {
24
+ const rank = new Map();
25
+ for (const rawLine of orderingLines) {
26
+ // ordering files written on Windows use `\` — convert it so they match on macOS and Linux too
27
+ let line = rawLine
28
+ .slice(rawLine.lastIndexOf(":") + 1)
29
+ .trim()
30
+ .replace(/\\/g, "/");
31
+ if (line.length === 0) {
32
+ continue;
33
+ }
34
+ if (line.startsWith("/")) {
35
+ line = line.slice(1);
36
+ }
37
+ // `path.normalize` keeps a trailing separator ("src/") that directory stream paths lack; a bare "/" is left alone
38
+ const key = path.normalize(line).replace(/(?<=.)[/\\]+$/, "");
39
+ if (!rank.has(key)) {
40
+ rank.set(key, rank.size);
41
+ }
42
+ }
43
+ if (rank.size === 0) {
44
+ return { streams, listed: 0, matched: 0, missing: [] };
45
+ }
46
+ const directories = [];
47
+ const listed = [];
48
+ const rest = [];
49
+ // entries are removed from `rank` as they are consumed, so what is left at the end is missing from the archive
50
+ for (const stream of streams) {
51
+ const key = path.normalize(stream.path);
52
+ if (stream.type === "directory") {
53
+ directories.push(stream);
54
+ // a line naming a directory orders nothing (directories hold no data), so it is neither listed nor missing
55
+ rank.delete(key);
56
+ continue;
57
+ }
58
+ const position = rank.get(key);
59
+ if (position == null) {
60
+ rest.push(stream);
61
+ }
62
+ else {
63
+ rank.delete(key);
64
+ listed.push({ stream, rank: position });
65
+ }
66
+ }
67
+ listed.sort((a, b) => a.rank - b.rank);
68
+ const missing = [...rank.keys()];
69
+ return { streams: [...directories, ...listed.map(it => it.stream), ...rest], listed: listed.length + missing.length, matched: listed.length, missing };
70
+ }
71
+ const ASAR_ORDERING_MIGRATION_URL = "https://www.electron.build/docs/migration/v27-breaking-changes#asar-ordering-is-now-applied";
72
+ /**
73
+ * Resolves `asar.ordering` like other build resources (build resources directory first, then the project directory),
74
+ * applies it to `streams` and announces the v27 behaviour change once per process.
75
+ * @internal
76
+ */
77
+ export async function applyAsarOrdering(packager, ordering, streams) {
78
+ const orderingFile = await resolveAsarOrderingFile(packager, ordering);
79
+ const { streams: ordered, listed, matched, missing } = orderAsarStreams(streams, (await fs.readFile(orderingFile, "utf8")).split(/\r?\n/));
80
+ const orderingPath = log.filePath(orderingFile);
81
+ log
82
+ .once("asar-ordering-applied")
83
+ .warn({ ordering: orderingPath }, "asar.ordering is now applied to app.asar (electron-builder v26 and earlier silently ignored it): the listed files are packed first, " +
84
+ "ahead of the default dependencies-first layout, which can increase differential update download size. " +
85
+ `Remove the option to keep the default layout. See ${ASAR_ORDERING_MIGRATION_URL}`);
86
+ log.once("asar-ordering", packager).info({ ordering: orderingPath, matched: `${matched}/${listed}` }, "applied asar ordering");
87
+ if (missing.length > 0) {
88
+ log.debug({ ordering: orderingPath, missing: missing.length, first: missing.slice(0, 5).join(", ") }, "asar ordering lists files that are not in the archive");
89
+ }
90
+ return ordered;
91
+ }
92
+ async function resolveAsarOrderingFile(packager, ordering) {
93
+ try {
94
+ return (await packager.getResource(ordering));
95
+ }
96
+ catch (e) {
97
+ if (!(e instanceof InvalidConfigurationError)) {
98
+ throw e;
99
+ }
100
+ const candidates = [...new Set([path.resolve(packager.buildResourcesDir, ordering), path.resolve(packager.projectDir, ordering)])];
101
+ throw new InvalidConfigurationError(`asar.ordering file "${ordering}" was not found at ${candidates.join(" or ")} ` +
102
+ "(the path resolves relative to the build resources directory, then the project directory). " +
103
+ "electron-builder v27 applies the ordering file to app.asar (v26 and earlier ignored the option), so it must exist; fix the path or remove the option to keep the default layout. " +
104
+ `See ${ASAR_ORDERING_MIGRATION_URL}`);
105
+ }
106
+ }
34
107
  /** @internal */
35
108
  export async function withElectronAsarLogging(task) {
36
109
  // override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)
@@ -62,8 +135,16 @@ export class AsarPackager {
62
135
  // Finish with the app files that change most often
63
136
  fileSets[0],
64
137
  ].map(set => this.orderFileSet(set));
65
- const streams = await this.processFileSets(orderedFileSets);
138
+ let streams = await this.processFileSets(orderedFileSets);
139
+ const ordering = this.config.options.ordering;
140
+ if (!isEmptyOrSpaces(ordering)) {
141
+ streams = await applyAsarOrdering(this.packager, ordering, streams);
142
+ }
66
143
  await this.executeElectronAsar(streams);
144
+ const contentAlignment = this.config.options.contentAlignment;
145
+ if (contentAlignment != null && contentAlignment !== 0) {
146
+ await alignAsarContent(this.outFile, contentAlignment);
147
+ }
67
148
  }
68
149
  async executeElectronAsar(streams) {
69
150
  await withElectronAsarLogging(async () => {
@@ -172,6 +253,9 @@ export class AsarPackager {
172
253
  if (!stat.isFile() && !stat.isSymbolicLink()) {
173
254
  return { path: destination, unpacked, type: "directory" };
174
255
  }
256
+ // verify that the file is not a direct link or symlinked to a file outside the workspace and the package-manager store,
257
+ // before any content is used: the transformer (e.g. for a node_modules package.json) reads the file through its symlinks too
258
+ await assertSourceFileInTrustedRoots(file, await getTrustedSourceRoots(this.packager), await this.packager.getExternalLinkPolicy());
175
259
  // Handle transformed data (pre-processed content)
176
260
  if (transformedData != null) {
177
261
  const size = Buffer.byteLength(transformedData);
@@ -188,8 +272,6 @@ export class AsarPackager {
188
272
  stat: { mode: stat.mode, size },
189
273
  };
190
274
  }
191
- // verify that the file is not a direct link or symlinked to access/copy a system file
192
- await this.protectSystemAndUnsafePaths(file, await this.packager.getWorkspaceRoot());
193
275
  const baseConfig = {
194
276
  path: destination,
195
277
  streamGenerator: () => fs.createReadStream(file),
@@ -252,37 +334,5 @@ export class AsarPackager {
252
334
  transformedFiles,
253
335
  };
254
336
  }
255
- async checkAgainstRoots(target, allowRoots) {
256
- const resolved = await resolvePath(target);
257
- if (resolved == null || isEmptyOrSpaces(resolved)) {
258
- return false;
259
- }
260
- for (const root of allowRoots) {
261
- if (resolved === root || resolved.startsWith(root + path.sep)) {
262
- return true;
263
- }
264
- }
265
- return false;
266
- }
267
- async protectSystemAndUnsafePaths(file, workspaceRoot) {
268
- const resolved = await resolvePath(file);
269
- const logFields = { source: file, realPath: resolved };
270
- const workspace = await resolvePath(workspaceRoot);
271
- // If in workspace, always safe
272
- if (workspace && resolved?.startsWith(workspace)) {
273
- return;
274
- }
275
- // Check allowlist (priority)
276
- if (await this.checkAgainstRoots(file, await ALLOWLIST)) {
277
- return;
278
- }
279
- // Check denylist
280
- if (await this.checkAgainstRoots(file, await DENYLIST)) {
281
- log.error(logFields, `denied access to system or unsafe path`);
282
- throw new Error(`Cannot copy file [${file}] symlinked to file [${resolved}] outside the package to a system or unsafe path`);
283
- }
284
- // Default: outside explicit paths but not explicitly denied
285
- log.debug(logFields, `path is outside of explicit safe paths, defaulting to safe`);
286
- }
287
337
  }
288
338
  //# sourceMappingURL=asarUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asarUtil.js","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAuB,eAAe,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAG5B,OAAO,EAAmB,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAA;AAEvB,MAAM,WAAW,GAAG,KAAK,EAAE,IAAwB,EAA+B,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,QAA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","sourcesContent":["import type { AsarStreamType, AsarDirectory } from \"@electron/asar\"\nimport { exists, Filter, FilterStats, isEmptyOrSpaces, log } from \"builder-util\"\nimport { dynamicImport } from \"../util/dynamicImport.js\"\nimport fs from \"fs-extra\"\n\nimport * as path from \"path\"\nimport { AsarOptions } from \"../options/PlatformSpecificBuildOptions.js\"\nimport { PlatformPackager } from \"../platformPackager.js\"\nimport { ResolvedFileSet, getDestinationPath } from \"../util/appFileCopier.js\"\nimport { detectUnpackedDirs } from \"./unpackDetector.js\"\nimport { Readable } from \"stream\"\nimport * as os from \"os\"\nconst { readlink } = fs\n\nconst resolvePath = async (file: string | undefined): Promise<string | undefined> => (file && (await exists(file)) ? fs.realpath(file).catch(() => path.resolve(file)) : undefined)\nconst resolvePaths = async (filepaths: (string | undefined)[]) => {\n return Promise.all(filepaths.map(resolvePath)).then(paths => paths.filter((it): it is string => it != null))\n}\n\nconst DENYLIST = resolvePaths([\n \"/usr\",\n \"/lib\",\n \"/bin\",\n \"/sbin\",\n \"/etc\",\n\n \"/tmp\",\n \"/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\n\n // macOS system directories\n \"/System\",\n \"/Library\",\n \"/private\",\n\n // Windows system directories\n process.env.SystemRoot,\n process.env.WINDIR,\n])\n\nconst ALLOWLIST = resolvePaths([\n os.tmpdir(), // always allow temp dir\n os.homedir(), // always allow home dir\n])\n\n/** @internal */\nexport async function withElectronAsarLogging<T>(task: () => Promise<T>): Promise<T> {\n // override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)\n const consoleLogger = console.log\n console.log = (...args) => {\n if (args[0] === \"Ordering file has 100% coverage.\") {\n return // no need to log, this means our ordering logic is working correctly\n }\n log.info({ args }, \"logging @electron/asar\")\n }\n try {\n return await task()\n } finally {\n console.log = consoleLogger\n }\n}\n\n/** @internal */\nexport class AsarPackager {\n private readonly outFile: string\n\n constructor(\n readonly packager: PlatformPackager<any>,\n private readonly config: {\n defaultDestination: string\n resourcePath: string\n options: AsarOptions\n unpackPattern: Filter | undefined\n }\n ) {\n this.outFile = path.join(config.resourcePath, `app.asar`)\n }\n\n async pack(fileSets: Array<ResolvedFileSet>) {\n const orderedFileSets = [\n // Write dependencies first to minimize offset changes to asar header\n ...fileSets.slice(1),\n\n // Finish with the app files that change most often\n fileSets[0],\n ].map(set => this.orderFileSet(set))\n\n const streams = await this.processFileSets(orderedFileSets)\n await this.executeElectronAsar(streams)\n }\n\n private async executeElectronAsar(streams: AsarStreamType[]) {\n await withElectronAsarLogging(async () => {\n const { createPackageFromStreams } = await dynamicImport<typeof import(\"@electron/asar\")>(\"@electron/asar\")\n await createPackageFromStreams(this.outFile, streams)\n })\n }\n\n private async processFileSets(fileSets: ResolvedFileSet[]): Promise<AsarStreamType[]> {\n const unpackedPaths = new Set<string>()\n if (this.config.options.smartUnpack !== false) {\n for (const fileSet of fileSets) {\n detectUnpackedDirs(fileSet, unpackedPaths)\n }\n }\n\n const resultsMap = new Map<string, AsarStreamType>()\n const streamOrdering: string[] = []\n const normalizedUnpackedPaths = Array.from(unpackedPaths).map(p => path.normalize(p))\n\n // Check whether a file or directory should be unpacked, using pre-normalized unpacked paths and early returns\n const isUnpacked = (dir: string, file?: string, stat?: FilterStats): boolean => {\n const normalizedDir = path.normalize(dir)\n\n // Check file pattern first (most specific)\n if (!isEmptyOrSpaces(file) && stat && this.config.unpackPattern?.(file, stat)) {\n return true\n }\n\n // Check if path is within any unpacked directory\n for (const unpackedPath of normalizedUnpackedPaths) {\n if (normalizedDir === unpackedPath || normalizedDir.startsWith(unpackedPath + path.sep)) {\n return true\n }\n }\n\n return false\n }\n\n // First pass: process all files in order, ensuring parent directories exist\n for (const fileSet of fileSets) {\n // Don't use Promise.all, we need to retain order of execution/iteration through the already-ordered fileset\n for (const [index, file] of fileSet.files.entries()) {\n const transformedData = fileSet.transformedFiles?.get(index)\n const stat = fileSet.metadata.get(file)!\n const destination = path.relative(this.config.defaultDestination, getDestinationPath(file, fileSet))\n\n // Ensure parent directories exist before processing file\n this.ensureParentDirectories(destination, resultsMap, streamOrdering)\n\n const result = await this.processFileOrSymlink({\n file,\n destination,\n fileSet,\n transformedData,\n stat,\n isUnpacked,\n })\n\n if (result && !resultsMap.has(result.path)) {\n resultsMap.set(result.path, result)\n streamOrdering.push(result.path)\n }\n }\n }\n\n // Second pass: propagate unpacked flag to parent directories\n for (const entry of resultsMap.values()) {\n if (entry.unpacked) {\n this.markParentDirectoriesAsUnpacked(entry.path, resultsMap, isUnpacked)\n }\n }\n\n // Build final results array maintaining processing order\n return streamOrdering.reduce<AsarStreamType[]>((streams, path) => {\n const stream = resultsMap.has(path) ? resultsMap.get(path) : null\n if (stream != null) {\n streams.push(stream)\n }\n return streams\n }, [])\n }\n\n private ensureParentDirectories(destination: string, resultsMap: Map<string, AsarStreamType>, streamOrdering: string[]): void {\n const parents: string[] = []\n let current = path.dirname(path.normalize(destination))\n\n // Collect all parent directories from deepest to root\n while (current !== \".\") {\n parents.unshift(current)\n current = path.dirname(current)\n }\n\n // Add parent directories in order (root to deepest)\n for (const parentPath of parents) {\n if (!resultsMap.has(parentPath)) {\n const dir: AsarDirectory = {\n type: \"directory\",\n path: parentPath,\n unpacked: false, // Updated in second pass if needed\n }\n resultsMap.set(parentPath, dir)\n streamOrdering.push(parentPath)\n }\n }\n }\n\n private markParentDirectoriesAsUnpacked(destination: string, resultsMap: Map<string, AsarStreamType>, isUnpacked: (path: string) => boolean): void {\n let current = path.dirname(path.normalize(destination))\n\n while (current !== \".\") {\n const entry = resultsMap.get(current)\n if (entry && isUnpacked(current)) {\n entry.unpacked = true\n }\n current = path.dirname(current)\n }\n }\n\n private async processFileOrSymlink(options: {\n file: string\n destination: string\n stat: fs.Stats\n fileSet: ResolvedFileSet\n transformedData: string | Buffer | undefined\n isUnpacked: (dir: string, file?: string, stat?: FilterStats) => boolean\n }): Promise<AsarStreamType> {\n const { isUnpacked, transformedData, file, destination, stat } = options\n const unpacked = isUnpacked(destination, file, stat)\n\n // Handle directories\n if (!stat.isFile() && !stat.isSymbolicLink()) {\n return { path: destination, unpacked, type: \"directory\" }\n }\n\n // Handle transformed data (pre-processed content)\n if (transformedData != null) {\n const size = Buffer.byteLength(transformedData)\n return {\n path: destination,\n streamGenerator: () =>\n new Readable({\n read() {\n this.push(transformedData)\n this.push(null)\n },\n }),\n unpacked,\n type: \"file\",\n stat: { mode: stat.mode, size },\n }\n }\n\n // verify that the file is not a direct link or symlinked to access/copy a system file\n await this.protectSystemAndUnsafePaths(file, await this.packager.getWorkspaceRoot())\n\n const baseConfig = {\n path: destination,\n streamGenerator: () => fs.createReadStream(file),\n unpacked,\n stat,\n }\n\n // Handle regular files\n if (!stat.isSymbolicLink()) {\n return { ...baseConfig, type: \"file\" }\n }\n\n // Handle symlinks - make relative to source location\n let link = await readlink(file)\n if (path.isAbsolute(link)) {\n link = path.relative(path.dirname(file), link)\n }\n\n return {\n ...baseConfig,\n type: \"link\",\n symlink: link,\n }\n }\n\n private orderFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {\n const sortedFileEntries = Array.from(fileSet.files.entries())\n\n sortedFileEntries.sort(([, a], [, b]) => {\n if (a === b) {\n return 0\n }\n\n // Place addons last because their signature changes per build\n const isAAddon = a.endsWith(\".node\")\n const isBAddon = b.endsWith(\".node\")\n if (isAAddon && !isBAddon) {\n return 1\n }\n if (isBAddon && !isAAddon) {\n return -1\n }\n\n // Otherwise order by name\n return a < b ? -1 : 1\n })\n\n let transformedFiles: Map<number, string | Buffer> | undefined\n if (fileSet.transformedFiles) {\n transformedFiles = new Map()\n\n const indexMap = new Map<number, number>()\n for (const [newIndex, [oldIndex]] of sortedFileEntries.entries()) {\n indexMap.set(oldIndex, newIndex)\n }\n\n for (const [oldIndex, value] of fileSet.transformedFiles) {\n const newIndex = indexMap.get(oldIndex)\n if (newIndex === undefined) {\n throw new Error(`Internal error: ${fileSet.files[oldIndex]} was lost while ordering asar`)\n }\n transformedFiles.set(newIndex, value)\n }\n }\n\n return {\n src: fileSet.src,\n destination: fileSet.destination,\n metadata: fileSet.metadata,\n files: sortedFileEntries.map(([, file]) => file),\n transformedFiles,\n }\n }\n\n private async checkAgainstRoots(target: string, allowRoots: string[]): Promise<boolean> {\n const resolved = await resolvePath(target)\n if (resolved == null || isEmptyOrSpaces(resolved)) {\n return false\n }\n\n for (const root of allowRoots) {\n if (resolved === root || resolved.startsWith(root + path.sep)) {\n return true\n }\n }\n return false\n }\n\n private async protectSystemAndUnsafePaths(file: string, workspaceRoot: string): Promise<void> {\n const resolved = await resolvePath(file)\n const logFields = { source: file, realPath: resolved }\n\n const workspace = await resolvePath(workspaceRoot)\n\n // If in workspace, always safe\n if (workspace && resolved?.startsWith(workspace)) {\n return\n }\n\n // Check allowlist (priority)\n if (await this.checkAgainstRoots(file, await ALLOWLIST)) {\n return\n }\n\n // Check denylist\n if (await this.checkAgainstRoots(file, await DENYLIST)) {\n log.error(logFields, `denied access to system or unsafe path`)\n throw new Error(`Cannot copy file [${file}] symlinked to file [${resolved}] outside the package to a system or unsafe path`)\n }\n\n // Default: outside explicit paths but not explicitly denied\n log.debug(logFields, `path is outside of explicit safe paths, defaulting to safe`)\n }\n}\n"]}
1
+ {"version":3,"file":"asarUtil.js","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,yBAAyB,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAG5B,OAAO,EAAmB,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EA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CAAA;gBAC5F,CAAC;gBACD,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;QAED,OAAO;YACL,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;YAChD,gBAAgB;SACjB,CAAA;IACH,CAAC;CACF","sourcesContent":["import type { AsarStreamType, AsarDirectory } from \"@electron/asar\"\nimport { Filter, FilterStats, InvalidConfigurationError, isEmptyOrSpaces, log } from \"builder-util\"\nimport { dynamicImport } from \"../util/dynamicImport.js\"\nimport fs from \"fs-extra\"\n\nimport * as path from \"path\"\nimport { AsarOptions } from \"../options/PlatformSpecificBuildOptions.js\"\nimport { PlatformPackager } from \"../platformPackager.js\"\nimport { ResolvedFileSet, getDestinationPath } from \"../util/appFileCopier.js\"\nimport { detectUnpackedDirs } from \"./unpackDetector.js\"\nimport { alignAsarContent } from \"./asarAlign.js\"\nimport { assertSourceFileInTrustedRoots, getTrustedSourceRoots } from \"../util/trustedSourceRoots.js\"\nimport { Readable } from \"stream\"\nconst { readlink } = fs\n\n/** @internal */\nexport function isPathInside(root: string, target: string): boolean {\n return target === root || target.startsWith(root + path.sep)\n}\n\n/**\n * Applies an asar ordering file (`asar.ordering`) to the stream list `@electron/asar` packs: directory entries move to\n * the front in their original relative order (they hold no data), the listed files follow in the order of the file,\n * then everything else in its original order. Lines use the same syntax `@electron/asar` accepts — a path relative to\n * the app root, optionally prefixed with `/` or with a `<anything>:` prefix (e.g. a load counter) — blank lines are\n * ignored and `\\` separators are accepted. Lines naming a directory are ignored; files listed but not present are\n * counted in `listed`, reported in `missing` and skipped.\n */\nexport function orderAsarStreams(\n streams: Array<AsarStreamType>,\n orderingLines: Array<string>\n): { streams: Array<AsarStreamType>; listed: number; matched: number; missing: Array<string> } {\n const rank = new Map<string, number>()\n for (const rawLine of orderingLines) {\n // ordering files written on Windows use `\\` — convert it so they match on macOS and Linux too\n let line = rawLine\n .slice(rawLine.lastIndexOf(\":\") + 1)\n .trim()\n .replace(/\\\\/g, \"/\")\n if (line.length === 0) {\n continue\n }\n if (line.startsWith(\"/\")) {\n line = line.slice(1)\n }\n // `path.normalize` keeps a trailing separator (\"src/\") that directory stream paths lack; a bare \"/\" is left alone\n const key = path.normalize(line).replace(/(?<=.)[/\\\\]+$/, \"\")\n if (!rank.has(key)) {\n rank.set(key, rank.size)\n }\n }\n if (rank.size === 0) {\n return { streams, listed: 0, matched: 0, missing: [] }\n }\n const directories: Array<AsarStreamType> = []\n const listed: Array<{ stream: AsarStreamType; rank: number }> = []\n const rest: Array<AsarStreamType> = []\n // entries are removed from `rank` as they are consumed, so what is left at the end is missing from the archive\n for (const stream of streams) {\n const key = path.normalize(stream.path)\n if (stream.type === \"directory\") {\n directories.push(stream)\n // a line naming a directory orders nothing (directories hold no data), so it is neither listed nor missing\n rank.delete(key)\n continue\n }\n const position = rank.get(key)\n if (position == null) {\n rest.push(stream)\n } else {\n rank.delete(key)\n listed.push({ stream, rank: position })\n }\n }\n listed.sort((a, b) => a.rank - b.rank)\n const missing = [...rank.keys()]\n return { streams: [...directories, ...listed.map(it => it.stream), ...rest], listed: listed.length + missing.length, matched: listed.length, missing }\n}\n\ntype AsarOrderingPackager = Pick<PlatformPackager<any>, \"getResource\" | \"buildResourcesDir\" | \"projectDir\">\n\nconst ASAR_ORDERING_MIGRATION_URL = \"https://www.electron.build/docs/migration/v27-breaking-changes#asar-ordering-is-now-applied\"\n\n/**\n * Resolves `asar.ordering` like other build resources (build resources directory first, then the project directory),\n * applies it to `streams` and announces the v27 behaviour change once per process.\n * @internal\n */\nexport async function applyAsarOrdering(packager: AsarOrderingPackager, ordering: string, streams: Array<AsarStreamType>): Promise<Array<AsarStreamType>> {\n const orderingFile = await resolveAsarOrderingFile(packager, ordering)\n const { streams: ordered, listed, matched, missing } = orderAsarStreams(streams, (await fs.readFile(orderingFile, \"utf8\")).split(/\\r?\\n/))\n const orderingPath = log.filePath(orderingFile)\n log\n .once(\"asar-ordering-applied\")\n .warn(\n { ordering: orderingPath },\n \"asar.ordering is now applied to app.asar (electron-builder v26 and earlier silently ignored it): the listed files are packed first, \" +\n \"ahead of the default dependencies-first layout, which can increase differential update download size. \" +\n `Remove the option to keep the default layout. See ${ASAR_ORDERING_MIGRATION_URL}`\n )\n log.once(\"asar-ordering\", packager).info({ ordering: orderingPath, matched: `${matched}/${listed}` }, \"applied asar ordering\")\n if (missing.length > 0) {\n log.debug({ ordering: orderingPath, missing: missing.length, first: missing.slice(0, 5).join(\", \") }, \"asar ordering lists files that are not in the archive\")\n }\n return ordered\n}\n\nasync function resolveAsarOrderingFile(packager: AsarOrderingPackager, ordering: string): Promise<string> {\n try {\n return (await packager.getResource(ordering))!\n } catch (e: any) {\n if (!(e instanceof InvalidConfigurationError)) {\n throw e\n }\n const candidates = [...new Set([path.resolve(packager.buildResourcesDir, ordering), path.resolve(packager.projectDir, ordering)])]\n throw new InvalidConfigurationError(\n `asar.ordering file \"${ordering}\" was not found at ${candidates.join(\" or \")} ` +\n \"(the path resolves relative to the build resources directory, then the project directory). \" +\n \"electron-builder v27 applies the ordering file to app.asar (v26 and earlier ignored the option), so it must exist; fix the path or remove the option to keep the default layout. \" +\n `See ${ASAR_ORDERING_MIGRATION_URL}`\n )\n }\n}\n\n/** @internal */\nexport async function withElectronAsarLogging<T>(task: () => Promise<T>): Promise<T> {\n // override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)\n const consoleLogger = console.log\n console.log = (...args) => {\n if (args[0] === \"Ordering file has 100% coverage.\") {\n return // no need to log, this means our ordering logic is working correctly\n }\n log.info({ args }, \"logging @electron/asar\")\n }\n try {\n return await task()\n } finally {\n console.log = consoleLogger\n }\n}\n\n/** @internal */\nexport class AsarPackager {\n private readonly outFile: string\n\n constructor(\n readonly packager: PlatformPackager<any>,\n private readonly config: {\n defaultDestination: string\n resourcePath: string\n options: AsarOptions\n unpackPattern: Filter | undefined\n }\n ) {\n this.outFile = path.join(config.resourcePath, `app.asar`)\n }\n\n async pack(fileSets: Array<ResolvedFileSet>) {\n const orderedFileSets = [\n // Write dependencies first to minimize offset changes to asar header\n ...fileSets.slice(1),\n\n // Finish with the app files that change most often\n fileSets[0],\n ].map(set => this.orderFileSet(set))\n\n let streams = await this.processFileSets(orderedFileSets)\n const ordering = this.config.options.ordering\n if (!isEmptyOrSpaces(ordering)) {\n streams = await applyAsarOrdering(this.packager, ordering, streams)\n }\n await this.executeElectronAsar(streams)\n\n const contentAlignment = this.config.options.contentAlignment\n if (contentAlignment != null && contentAlignment !== 0) {\n await alignAsarContent(this.outFile, contentAlignment)\n }\n }\n\n private async executeElectronAsar(streams: AsarStreamType[]) {\n await withElectronAsarLogging(async () => {\n const { createPackageFromStreams } = await dynamicImport<typeof import(\"@electron/asar\")>(\"@electron/asar\")\n await createPackageFromStreams(this.outFile, streams)\n })\n }\n\n private async processFileSets(fileSets: ResolvedFileSet[]): Promise<AsarStreamType[]> {\n const unpackedPaths = new Set<string>()\n if (this.config.options.smartUnpack !== false) {\n for (const fileSet of fileSets) {\n detectUnpackedDirs(fileSet, unpackedPaths)\n }\n }\n\n const resultsMap = new Map<string, AsarStreamType>()\n const streamOrdering: string[] = []\n const normalizedUnpackedPaths = Array.from(unpackedPaths).map(p => path.normalize(p))\n\n // Check whether a file or directory should be unpacked, using pre-normalized unpacked paths and early returns\n const isUnpacked = (dir: string, file?: string, stat?: FilterStats): boolean => {\n const normalizedDir = path.normalize(dir)\n\n // Check file pattern first (most specific)\n if (!isEmptyOrSpaces(file) && stat && this.config.unpackPattern?.(file, stat)) {\n return true\n }\n\n // Check if path is within any unpacked directory\n for (const unpackedPath of normalizedUnpackedPaths) {\n if (normalizedDir === unpackedPath || normalizedDir.startsWith(unpackedPath + path.sep)) {\n return true\n }\n }\n\n return false\n }\n\n // First pass: process all files in order, ensuring parent directories exist\n for (const fileSet of fileSets) {\n // Don't use Promise.all, we need to retain order of execution/iteration through the already-ordered fileset\n for (const [index, file] of fileSet.files.entries()) {\n const transformedData = fileSet.transformedFiles?.get(index)\n const stat = fileSet.metadata.get(file)!\n const destination = path.relative(this.config.defaultDestination, getDestinationPath(file, fileSet))\n\n // Ensure parent directories exist before processing file\n this.ensureParentDirectories(destination, resultsMap, streamOrdering)\n\n const result = await this.processFileOrSymlink({\n file,\n destination,\n fileSet,\n transformedData,\n stat,\n isUnpacked,\n })\n\n if (result && !resultsMap.has(result.path)) {\n resultsMap.set(result.path, result)\n streamOrdering.push(result.path)\n }\n }\n }\n\n // Second pass: propagate unpacked flag to parent directories\n for (const entry of resultsMap.values()) {\n if (entry.unpacked) {\n this.markParentDirectoriesAsUnpacked(entry.path, resultsMap, isUnpacked)\n }\n }\n\n // Build final results array maintaining processing order\n return streamOrdering.reduce<AsarStreamType[]>((streams, path) => {\n const stream = resultsMap.has(path) ? resultsMap.get(path) : null\n if (stream != null) {\n streams.push(stream)\n }\n return streams\n }, [])\n }\n\n private ensureParentDirectories(destination: string, resultsMap: Map<string, AsarStreamType>, streamOrdering: string[]): void {\n const parents: string[] = []\n let current = path.dirname(path.normalize(destination))\n\n // Collect all parent directories from deepest to root\n while (current !== \".\") {\n parents.unshift(current)\n current = path.dirname(current)\n }\n\n // Add parent directories in order (root to deepest)\n for (const parentPath of parents) {\n if (!resultsMap.has(parentPath)) {\n const dir: AsarDirectory = {\n type: \"directory\",\n path: parentPath,\n unpacked: false, // Updated in second pass if needed\n }\n resultsMap.set(parentPath, dir)\n streamOrdering.push(parentPath)\n }\n }\n }\n\n private markParentDirectoriesAsUnpacked(destination: string, resultsMap: Map<string, AsarStreamType>, isUnpacked: (path: string) => boolean): void {\n let current = path.dirname(path.normalize(destination))\n\n while (current !== \".\") {\n const entry = resultsMap.get(current)\n if (entry && isUnpacked(current)) {\n entry.unpacked = true\n }\n current = path.dirname(current)\n }\n }\n\n private async processFileOrSymlink(options: {\n file: string\n destination: string\n stat: fs.Stats\n fileSet: ResolvedFileSet\n transformedData: string | Buffer | undefined\n isUnpacked: (dir: string, file?: string, stat?: FilterStats) => boolean\n }): Promise<AsarStreamType> {\n const { isUnpacked, transformedData, file, destination, stat } = options\n const unpacked = isUnpacked(destination, file, stat)\n\n // Handle directories\n if (!stat.isFile() && !stat.isSymbolicLink()) {\n return { path: destination, unpacked, type: \"directory\" }\n }\n\n // verify that the file is not a direct link or symlinked to a file outside the workspace and the package-manager store,\n // before any content is used: the transformer (e.g. for a node_modules package.json) reads the file through its symlinks too\n await assertSourceFileInTrustedRoots(file, await getTrustedSourceRoots(this.packager), await this.packager.getExternalLinkPolicy())\n\n // Handle transformed data (pre-processed content)\n if (transformedData != null) {\n const size = Buffer.byteLength(transformedData)\n return {\n path: destination,\n streamGenerator: () =>\n new Readable({\n read() {\n this.push(transformedData)\n this.push(null)\n },\n }),\n unpacked,\n type: \"file\",\n stat: { mode: stat.mode, size },\n }\n }\n\n const baseConfig = {\n path: destination,\n streamGenerator: () => fs.createReadStream(file),\n unpacked,\n stat,\n }\n\n // Handle regular files\n if (!stat.isSymbolicLink()) {\n return { ...baseConfig, type: \"file\" }\n }\n\n // Handle symlinks - make relative to source location\n let link = await readlink(file)\n if (path.isAbsolute(link)) {\n link = path.relative(path.dirname(file), link)\n }\n\n return {\n ...baseConfig,\n type: \"link\",\n symlink: link,\n }\n }\n\n private orderFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {\n const sortedFileEntries = Array.from(fileSet.files.entries())\n\n sortedFileEntries.sort(([, a], [, b]) => {\n if (a === b) {\n return 0\n }\n\n // Place addons last because their signature changes per build\n const isAAddon = a.endsWith(\".node\")\n const isBAddon = b.endsWith(\".node\")\n if (isAAddon && !isBAddon) {\n return 1\n }\n if (isBAddon && !isAAddon) {\n return -1\n }\n\n // Otherwise order by name\n return a < b ? -1 : 1\n })\n\n let transformedFiles: Map<number, string | Buffer> | undefined\n if (fileSet.transformedFiles) {\n transformedFiles = new Map()\n\n const indexMap = new Map<number, number>()\n for (const [newIndex, [oldIndex]] of sortedFileEntries.entries()) {\n indexMap.set(oldIndex, newIndex)\n }\n\n for (const [oldIndex, value] of fileSet.transformedFiles) {\n const newIndex = indexMap.get(oldIndex)\n if (newIndex === undefined) {\n throw new Error(`Internal error: ${fileSet.files[oldIndex]} was lost while ordering asar`)\n }\n transformedFiles.set(newIndex, value)\n }\n }\n\n return {\n src: fileSet.src,\n destination: fileSet.destination,\n metadata: fileSet.metadata,\n files: sortedFileEntries.map(([, file]) => file),\n transformedFiles,\n }\n }\n}\n"]}
@@ -659,7 +659,7 @@ export interface ToolsetConfig {
659
659
  * Version of the AppImage toolset bundle used for building `.AppImage` files.
660
660
  *
661
661
  * The bundle ships:
662
- * - **`mksquashfs`** — creates the SquashFS filesystem embedded in the AppImage.
662
+ * - **`mksquashfs`** — creates the SquashFS filesystem embedded in the AppImage. It also packs legacy-base (core18/core20/core22) snaps built from the snap template app.
663
663
  * - **`desktop-file-validate`** — validates the generated `.desktop` entry.
664
664
  * - **AppImage runtime** — the self-executing stub that mounts the SquashFS at launch.
665
665
  *
@@ -670,6 +670,8 @@ export interface ToolsetConfig {
670
670
  * | `"1.0.3"` | 20251108 | Introduces static AppImage runtime |
671
671
  * | `"1.1.0"` | 20251108 | Adds `unsquashfs` support |
672
672
  *
673
+ * An explicit version pin always selects exactly that release.
674
+ *
673
675
  * Releases: https://github.com/electron-userland/electron-builder-binaries/blob/master/packages/appimage/CHANGELOG.md
674
676
  *
675
677
  * @default "latest"
@@ -1031,9 +1033,9 @@ export interface MetadataDirectories {
1031
1033
  * custom NSIS scripts, etc.) that electron-builder reads during packaging.
1032
1034
  *
1033
1035
  * **Build resources are not copied into the packaged app.** If you need runtime access to a
1034
- * file (e.g. a tray icon), include it explicitly via the `files` option:
1036
+ * file (e.g. a tray icon), include it explicitly via the `fileOptions.files` option:
1035
1037
  * ```json
1036
- * { "files": ["**\/*", "build/icon.*"] }
1038
+ * { "fileOptions": { "files": ["**\/*", "build/icon.*"] } }
1037
1039
  * ```
1038
1040
  *
1039
1041
  * @default "build"